Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
run: go run github.com/rhysd/actionlint/cmd/actionlint@v1.7.12 -color=false
- run: node --test scripts/ci-selection.test.mjs scripts/ci-results.test.mjs scripts/prepare-contract-report.test.mjs
- run: node --test scripts/prepare-pages-reports.test.mjs
- run: node --test scripts/deployment-smoke.test.mjs
- run: python3 -m unittest discover -s scripts -p railway_preview_qr_test.py

railway-config:
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/deployment-smoke.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Public deployment smoke

on:
workflow_dispatch:

permissions:
contents: read

jobs:
smoke:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 22.20.0
- name: Probe fixed public Lovat endpoints
run: |
set -o pipefail
{
echo "Smoke runner revision: $GITHUB_SHA"
node scripts/deployment-smoke.mjs
} | tee deployment-smoke.log
- name: Retain smoke evidence
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: deployment-smoke-${{ github.run_id }}-${{ github.run_attempt }}
path: deployment-smoke.log
retention-days: 14
if-no-files-found: warn
26 changes: 26 additions & 0 deletions docs/deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,29 @@ For Railway service roots and the plan/apply process, use [Railway configuration
4. Record the tested revision and verify a rollback path before promoting to production.

[Test report hosting](../test-report-hosting.md) covers the separate GitHub Pages test site.

## Public production smoke checks

After a production deployment, run **Public deployment smoke** from the repository's
Actions tab on `main`, or run `node scripts/deployment-smoke.mjs` with Node 22.20.0.
It checks the deployed Website home, Learn root redirect and Welcome guide,
Dashboard shell and JavaScript entry point, and the public API `/status` and
`/version` contracts. The target domains and paths are fixed in the script.
It sends only bounded, anonymous GET requests, never follows redirects, and
retries timeouts, network errors, 429s and 5xx responses once for cold starts.
This is a manual check, not a periodic probe that could wake a sleeping service.

Record the deployment SHA/ID separately from the smoke runner commit, and link
the Actions run to the release notes or incident. The run publishes a short log
as a 14-day artifact on success or probe failure. It logs the fixed endpoint,
status, elapsed time, retry count and failure category, not response contents or
arbitrary response headers. An overall failure is evidence to investigate,
not an automatic rollback: verify the deployed revision, check the provider and
service logs, and decide whether to repair or restore the last healthy release.

`/status` is the current public **process** status, not dependency readiness.
This check does not establish PostgreSQL/Redis health, verify a deployed SHA,
exercise authenticated reads or submissions, or monitor production continuously.
Dependency readiness and shutdown remain in [LVT-339](https://linear.app/highlander-robotics/issue/LVT-339).
An authorized synthetic read, isolated test report, alerts, service metrics and
rollback rehearsal remain in [LVT-347](https://linear.app/highlander-robotics/issue/LVT-347).
207 changes: 207 additions & 0 deletions scripts/deployment-smoke.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
import { performance } from "node:perf_hooks";
import { setTimeout as delay } from "node:timers/promises";
import { pathToFileURL } from "node:url";

const timeoutMs = 12_000;
const bodyLimit = 32 * 1024;
const checks = [
{
name: "Website home",
url: "https://lovat.app/",
mime: "text/html",
html: /<title>\s*Lovat\s*(?:—|&mdash;|&#8212;)\s*Centralize your team/i,
},
{
name: "Learn root redirect",
url: "https://learn.lovat.app/",
redirect: "https://learn.lovat.app/guides/welcome/",
},
{
name: "Learn Welcome guide",
url: "https://learn.lovat.app/guides/welcome/",
mime: "text/html",
html: /<title>\s*Welcome\b/i,
},
{
name: "Dashboard web shell",
url: "https://dashboard.lovat.app/",
mime: "text/html",
html: /<title>\s*Lovat\s*<\/title>/i,
},
{
name: "Dashboard application script",
url: "https://dashboard.lovat.app/main.dart.js",
mime: ["text/javascript", "application/javascript", "application/x-javascript"],
},
{
name: "API process status",
url: "https://api.lovat.app/status",
exact: "Server running",
},
{
name: "API version contract",
url: "https://api.lovat.app/version",
mime: "application/json",
validate: (body) => {
const version = JSON.parse(body);
return (
typeof version?.version === "string" &&
/^\d+\.\d+\.\d+$/.test(version.version) &&
typeof version.gitCommit === "string" &&
version.gitCommit.length > 0
);
},
},
];

async function readPrefix(body, limit, pattern) {
if (!body) return { text: "", truncated: false };

const reader = body.getReader();
const decoder = new TextDecoder();
let text = "";
let remaining = limit;
try {
for (;;) {
const { value, done } = await reader.read();
if (done) return { text: text + decoder.decode(), truncated: false };

text += decoder.decode(value.subarray(0, remaining), { stream: true });
if (pattern?.test(text)) return { text, truncated: false };

remaining -= value.length;
if (remaining <= 0) return { text, truncated: true };
}
} finally {
// Cancelling prevents reading the full HTML or asset on a smoke request.
void reader.cancel().catch(() => {});
}
}

async function probe(check, fetcher, deadline) {
let response;
try {
response = await fetcher(check.url, {
method: "GET",
credentials: "omit",
redirect: "manual",
signal: deadline,
});

const { status } = response;
if (status >= 500 || status === 429) {
return { status, reason: "transient HTTP status", retryable: true };
}

if (check.redirect) {
let destination;
try {
const location = response.headers.get("location");
if (location) destination = new URL(location, check.url).href;
} catch {
// Invalid redirect locations fail without logging response content.
}
return [302, 307].includes(status) && destination === check.redirect
? { status }
: { status, reason: "unexpected redirect" };
}

if (status !== 200) return { status, reason: "unexpected HTTP status" };

if (check.mime) {
const mediaType = response.headers
.get("content-type")
?.split(";")[0]
.trim()
.toLowerCase();
if (![check.mime].flat().includes(mediaType)) {
return { status, reason: "unexpected content type" };
}
}

if (check.html || check.exact || check.validate) {
const { text, truncated } = await readPrefix(
response.body,
check.html ? bodyLimit : 4096,
check.html,
);
try {
const valid = check.html
? check.html.test(text)
: !truncated && (check.validate ? check.validate(text) : text.trim() === check.exact);
if (!valid) return { status, reason: "unexpected response content" };
} catch {
return { status, reason: "unexpected response content" };
}
}
return { status };
} catch {
return {
status: response?.status ?? null,
reason: deadline.aborted ? "request timed out" : "network or response read error",
retryable: true,
};
} finally {
if (response?.body && !response.body.locked) {
void response.body.cancel().catch(() => {});
}
}
}

export async function runDeploymentSmoke({
fetcher = fetch,
pause = delay,
makeDeadline = () => AbortSignal.timeout(timeoutMs),
} = {}) {
return Promise.all(
checks.map(async (check) => {
const started = performance.now();
const first = await probe(check, fetcher, makeDeadline());
if (first.retryable) await pause(1000);
const last = first.retryable
? await probe(check, fetcher, makeDeadline())
: first;

return {
name: check.name,
url: check.url,
ok: !last.reason,
status: last.status,
attempts: first.retryable ? 2 : 1,
durationMs: Math.round(performance.now() - started),
...(first.retryable && {
firstAttempt: { status: first.status, reason: first.reason },
}),
...(last.reason && { reason: last.reason }),
};
}),
);
}

async function main() {
if (process.argv.length !== 2) {
console.error("Usage: node scripts/deployment-smoke.mjs (no arguments)");
process.exitCode = 2;
return;
}

console.log(`Lovat public production smoke | ${new Date().toISOString()}`);
const results = await runDeploymentSmoke();
for (const check of results) {
const status = check.status === null ? "no HTTP response" : `HTTP ${check.status}`;
const prior = check.firstAttempt
? `; first attempt: ${check.firstAttempt.reason}${check.firstAttempt.status === null ? "" : ` (HTTP ${check.firstAttempt.status})`}`
: "";
const problem = check.reason ? `; ${check.reason}` : "";
console.log(
`${check.ok ? "PASS" : "FAIL"} ${check.name} [${check.url}]: ${status}, ${check.durationMs}ms, ${check.attempts} attempt(s)${prior}${problem}`,
);
}
const passed = results.filter((check) => check.ok).length;
console.log(`${passed}/${results.length} public checks passed`);
if (passed !== results.length) process.exitCode = 1;
}

if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
await main();
}
Loading
Loading