Skip to content

Commit c4ff318

Browse files
committed
[red] Guard active installer continuity
Signed-off-by: Viwat Vchirawongkwin <viwat.v@chula.ac.th> (cherry picked from commit 83bb9062d5406e413419d7289d447870753404c0)
1 parent c2cf0af commit c4ff318

2 files changed

Lines changed: 101 additions & 0 deletions

File tree

‎tools/web/src/test/vps-deployment-contract.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,31 @@ describe("Cloudflare-fronted VPS deployment", () => {
436436
expect(cleanOutputAssertionIndex).toBeGreaterThan(buildIndex);
437437
});
438438

439+
it("cannot silently replace an active installer with the unavailable page", async () => {
440+
const script = await readFile(
441+
join(deploymentRoot, "vps", "deploy.sh"),
442+
"utf8",
443+
);
444+
const marker = ".pyble-firmware-release-selection.json";
445+
const buildIndex = script.indexOf(
446+
"NEXT_TELEMETRY_DISABLED=1 npm run check",
447+
);
448+
const markerLookup = script.indexOf(marker);
449+
const explicitDisable = script.indexOf(
450+
"PYBLE_EXPLICITLY_DISABLE_PUBLIC_INSTALLER",
451+
);
452+
453+
expect(markerLookup).toBeGreaterThan(-1);
454+
expect(markerLookup).toBeLessThan(buildIndex);
455+
expect(explicitDisable).toBeGreaterThan(-1);
456+
expect(explicitDisable).toBeLessThan(buildIndex);
457+
expect
458+
.soft(script.slice(Math.min(markerLookup, explicitDisable), buildIndex))
459+
.toMatch(
460+
/(?:preserv|carry|current)[\s\S]{0,2400}(?:Refusing|exit\s+65|--verify-staged)/i,
461+
);
462+
});
463+
439464
it("rejects every Next production dotenv input before a nominal website-only build", async () => {
440465
const script = await readFile(
441466
join(deploymentRoot, "vps", "deploy.sh"),

‎tools/web/src/test/vps-self-hosted-release-contract.test.ts‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,82 @@ beforeAll(async () => {
1414
});
1515

1616
describe("self-hosted firmware activation", () => {
17+
it("carries an active public installer through later website-only deployments", () => {
18+
const stagedBranch = script.indexOf(
19+
"if [[ -n ${PYBLE_FIRMWARE_STAGED_ROOT:-} ]]; then",
20+
);
21+
const build = script.indexOf("NEXT_TELEMETRY_DISABLED=1 npm run check");
22+
const marker = ".pyble-firmware-release-selection.json";
23+
const currentRelease = script.indexOf("/srv/pyble/current");
24+
const authenticatedRetrieval = script.search(
25+
/\b(?:ssh|rsync)\b[\s\S]{0,2400}\.pyble-firmware-release-selection\.json/,
26+
);
27+
const preservedValidation = script.indexOf(
28+
"--verify-staged",
29+
authenticatedRetrieval,
30+
);
31+
32+
expect.soft(script).toContain(marker);
33+
expect.soft(currentRelease).toBeGreaterThan(-1);
34+
expect
35+
.soft(
36+
authenticatedRetrieval,
37+
"the current selector and immutable firmware must be retrieved over the authenticated deployment transport",
38+
)
39+
.toBeGreaterThan(-1);
40+
expect.soft(authenticatedRetrieval).toBeLessThan(build);
41+
expect.soft(preservedValidation).toBeGreaterThan(authenticatedRetrieval);
42+
expect.soft(preservedValidation).toBeLessThan(build);
43+
expect
44+
.soft(script.slice(authenticatedRetrieval, build))
45+
.toContain("PYBLE_FLASH_SELECTION_FILE");
46+
expect
47+
.soft(script.slice(stagedBranch, build))
48+
.toMatch(/deployment\s*!==\s*"public"[\s\S]*hilStatus\s*!==\s*"passed"/);
49+
});
50+
51+
it("requires an unambiguous explicit operation to disable an active installer", () => {
52+
const flag = "PYBLE_EXPLICITLY_DISABLE_PUBLIC_INSTALLER";
53+
const flagIndex = script.indexOf(flag);
54+
const stagedBranch = script.indexOf(
55+
"if [[ -n ${PYBLE_FIRMWARE_STAGED_ROOT:-} ]]; then",
56+
);
57+
const build = script.indexOf("NEXT_TELEMETRY_DISABLED=1 npm run check");
58+
59+
expect.soft(flagIndex).toBeGreaterThan(-1);
60+
expect.soft(flagIndex).toBeLessThan(stagedBranch);
61+
expect
62+
.soft(script.slice(flagIndex, build))
63+
.toMatch(/(?:0\|1|"0"\|"1"|!=\s*"0"[\s\S]*!=\s*"1")/);
64+
expect
65+
.soft(script.slice(flagIndex, build))
66+
.toMatch(
67+
/PYBLE_EXPLICITLY_DISABLE_PUBLIC_INSTALLER[\s\S]{0,1600}PYBLE_FIRMWARE_STAGED_ROOT[\s\S]{0,800}(?:Refusing|exit\s+65)/,
68+
);
69+
expect
70+
.soft(script.slice(flagIndex, build))
71+
.toMatch(/(?:disabled|unavailable)[\s\S]{0,1200}(?:flash\.html|smoke)/i);
72+
});
73+
74+
it("retains the validated selector as hidden state in each active website release", () => {
75+
const marker = ".pyble-firmware-release-selection.json";
76+
const build = script.indexOf("NEXT_TELEMETRY_DISABLED=1 npm run check");
77+
const markerCopy = script.indexOf(marker, build);
78+
const upload = script.search(/\brsync\b/);
79+
const smoke = script.indexOf("for route in / /privacy /support /flash");
80+
81+
expect(markerCopy).toBeGreaterThan(build);
82+
expect(markerCopy).toBeLessThan(upload);
83+
expect
84+
.soft(script.slice(markerCopy - 300, markerCopy + 600))
85+
.toMatch(/(?:cp|install)[\s\S]*\$\{staged_selection\}/);
86+
expect
87+
.soft(script.slice(smoke))
88+
.toMatch(
89+
/\.pyble-firmware-release-selection\.json[\s\S]{0,2400}(?:flash\.html|\/flash)/,
90+
);
91+
});
92+
1793
it("accepts only a canonically validated all-HIL-passed public staged release", () => {
1894
const stagedBranch = script.indexOf(
1995
"if [[ -n ${PYBLE_FIRMWARE_STAGED_ROOT:-} ]]; then",

0 commit comments

Comments
 (0)