Skip to content

Commit 34ddb4d

Browse files
authored
fix(release): pipeline correctness for Windows packaging, checksums, publication ordering, and process identity (#5388)
* fix(release): run Windows packaging scripts under bash and record verifiable checksums The Windows desktop packaging lane ran a bash script under the runner default shell: Rename release assets uses backslash continuations and "$VAR" expansion with no shell: bash, and the workflow sets no defaults.run.shell, so a Windows runner reads it as PowerShell. The standalone archive step also wrote checksums naming a dist/ path, while attach-release verifies them with shasum -c from inside dist/release, where no dist/ directory exists. The step now declares shell: bash, and the checksum records the bare file name it is verified against. The contract is enforced by tests/ci-workflows/release-pipeline-contract.test.ts: every multi-line script on a Windows runner must declare an explicit shell, and a checksum argument must not carry a directory prefix the verifier cannot resolve. Both were driven red against the unfixed workflow before this change. * fix(release): gate npm publication and the GitHub release on packaging publish declared needs: validate-dispatch only, so npm publication and the GitHub release could proceed while desktop packaging was still failing, which is how a version becomes public with no app attached. The job now waits for package-standalone and package-desktop, matching the ordering attach-release already demanded of it. The release-pipeline contract test asserts the publish and attach-release dependency sets, and the long-standing assertion in ci-workflows.test.ts that encoded the old single-dependency shape is updated to the gated one. Driven red before the change. * fix(ci): trigger service lifecycle on the whole service directory and the desktop shell The lifecycle workflow and the release gate both keyed on src/service.ts, but the service implementation is the eleven-file src/service/ directory, and neither covered desktop/, whose shell packages and launches the service. A change to launchd.ts or windows-scheduler.ts alone produced no lifecycle run, and a release touching those files would have gated on evidence that never ran. Both triggers and the release gate regex now cover src/service/** and desktop/**, kept in sync in both files. The contract test derives the service module and desktop surface lists from the tree itself rather than restating them, so a new file that falls outside the gate fails the test. Driven red before the change. * fix(config): recognise the standalone Windows ocx.exe in process identity isOcxCommandLine matched ocx and ocx.cmd but not ocx.exe, even though scripts/build-standalone.ts and desktop/scripts/prepare-sidecar.ts both emit ocx.exe on Windows targets and the bundled sidecar is copied as ocx-<triple>.exe. The predicate feeds pid identity, so the shipped Windows binary was the one shape the identity check did not know: a service restart or a receipt-backed stop could not tell its own process from a foreign one. The executable token now accepts .exe as well as .cmd, so a quoted install path with spaces and any letter case matches, while lookalikes such as not-ocx.exe, myocx.exe and ocx.exes stay foreign. Driven red in tests/service/process-state.test.ts before the change. * fix(desktop): force the management client direct to loopback ProxyClient sends the admin token to 127.0.0.1, but reqwest resolves system proxy configuration by default, so a machine-wide proxy would receive a credential that is only ever meant for loopback. The builder now disables proxy resolution explicitly. tests/clients/desktop-proxy-direct-transport.test.ts asserts the builder carries no_proxy(), driven red before the change.
1 parent d6c256e commit 34ddb4d

10 files changed

Lines changed: 249 additions & 11 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,12 @@ jobs:
155155
else
156156
tar -czf "../../ocx-${RELEASE_VERSION}-${STANDALONE_TARGET}.tar.gz" ocx gui
157157
fi
158-
cd ../../..
159-
if [[ "$RUNNER_OS" == "Windows" ]]; then sha256sum "dist/ocx-${RELEASE_VERSION}-${STANDALONE_TARGET}.zip" > "dist/ocx-${RELEASE_VERSION}-${STANDALONE_TARGET}.sha256"
160-
else sha256sum "dist/ocx-${RELEASE_VERSION}-${STANDALONE_TARGET}.tar.gz" > "dist/ocx-${RELEASE_VERSION}-${STANDALONE_TARGET}.sha256"
158+
cd ../..
159+
# shasum -c in attach-release runs from dist/release, where the artifact download
160+
# lands these files flat; the checksum therefore records the bare file name, which
161+
# sha256sum takes verbatim from its argument.
162+
if [[ "$RUNNER_OS" == "Windows" ]]; then sha256sum "ocx-${RELEASE_VERSION}-${STANDALONE_TARGET}.zip" > "ocx-${RELEASE_VERSION}-${STANDALONE_TARGET}.sha256"
163+
else sha256sum "ocx-${RELEASE_VERSION}-${STANDALONE_TARGET}.tar.gz" > "ocx-${RELEASE_VERSION}-${STANDALONE_TARGET}.sha256"
161164
fi
162165
163166
- name: Upload standalone release
@@ -345,6 +348,7 @@ jobs:
345348
run: bunx tauri build --ci --target ${{ matrix.target }} --bundles ${{ matrix.bundles }}
346349

347350
- name: Rename release assets
351+
shell: bash
348352
env:
349353
RELEASE_VERSION: ${{ inputs.version }}
350354
DESKTOP_TARGET: ${{ matrix.target }}
@@ -481,7 +485,7 @@ jobs:
481485
gh release upload "v${RELEASE_VERSION}" dist/release/* --clobber
482486
483487
publish:
484-
needs: validate-dispatch
488+
needs: [validate-dispatch, package-standalone, package-desktop]
485489
runs-on: ubuntu-latest
486490
timeout-minutes: 15
487491
permissions:
@@ -632,8 +636,10 @@ jobs:
632636
fi
633637
634638
# Keep in sync with the service-lifecycle.yml trigger paths. src/cli.ts is
635-
# the pre-restructure compat stub that durable launchers still execute.
636-
if printf '%s\n' "$changed_files" | grep -Eq '^(src/service\.ts|src/cli\.ts|src/cli/index\.ts|src/lib/bun-runtime\.ts|package\.json|bun\.lock|\.github/workflows/service-lifecycle\.yml|\.github/workflows/release\.yml)$'; then
639+
# the pre-restructure compat stub that durable launchers still execute; the
640+
# service implementation itself is the src/service/ directory, and the desktop
641+
# shell packages and launches it.
642+
if printf '%s\n' "$changed_files" | grep -Eq '^(src/service\.ts|src/service/.*|desktop/.*|src/cli\.ts|src/cli/index\.ts|src/lib/bun-runtime\.ts|package\.json|bun\.lock|\.github/workflows/service-lifecycle\.yml|\.github/workflows/release\.yml)$'; then
637643
service_url="$(
638644
gh run list \
639645
--workflow service-lifecycle.yml \

‎.github/workflows/service-lifecycle.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ on:
55
branches: [main, dev]
66
paths:
77
- "src/service.ts"
8+
# The service implementation is the src/service/ directory; src/service.ts is only
9+
# the pre-restructure compat facade. The desktop shell packages and launches the
10+
# service, so its changes carry lifecycle evidence too.
11+
- "src/service/**"
12+
- "desktop/**"
813
# Keep in sync with the release.yml service-gate regex (release.yml "Require
914
# successful Cross-platform CI" step). src/cli.ts is the pre-restructure compat
1015
# stub that durable launchers still execute.
@@ -22,6 +27,9 @@ on:
2227
paths:
2328
- "src/service.ts"
2429
# Keep in sync with the release.yml service-gate regex (see above).
30+
- "src/service/**"
31+
- "desktop/**"
32+
# Keep in sync with the release.yml service-gate regex (see above).
2533
- "src/cli.ts"
2634
- "src/cli/index.ts"
2735
- "src/lib/bun-runtime.ts"

‎desktop/src-tauri/src/proxy.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ impl ProxyClient {
2424
client: Client::builder()
2525
.timeout(Duration::from_secs(4))
2626
.user_agent(Auth::user_agent())
27+
// The admin token attached to these requests is for loopback only.
28+
// reqwest honours system proxy configuration by default, which would
29+
// route the credential through whatever proxy the machine declares.
30+
.no_proxy()
2731
.build()?,
2832
endpoint,
2933
auth,

‎scripts/test-layout/layout.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,9 @@
16361636
"ambiguous-resend-gate.test.ts": "lib",
16371637
"docs-developer-role-policy.test.ts": "ci-workflows",
16381638
"ambiguous-resend-composition.test.ts": "lib",
1639-
"chat-inbound-developer-position.test.ts": "responses"
1639+
"chat-inbound-developer-position.test.ts": "responses",
1640+
"release-pipeline-contract.test.ts": "ci-workflows",
1641+
"desktop-proxy-direct-transport.test.ts": "clients"
16401642
},
16411643
"migrated": [
16421644
"adapters",

‎src/config/process-state.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export function isOcxCommandLine(commandLine: string): boolean {
127127
|| normalized.includes("src/cli/index.ts")
128128
|| normalized.includes("@bitkyc08/opencodex")
129129
|| /@bitkyc08\/\.opencodex-/.test(normalized)
130-
|| /(?:^|[\s/"'])(?:ocx|opencodex)(?:\.cmd)?(?:$|[\s"'])/.test(normalized);
130+
|| /(?:^|[\s/"'])(?:ocx|opencodex)(?:\.cmd|\.exe)?(?:$|[\s"'])/.test(normalized);
131131
}
132132

133133
export function isOcxStartCommandLine(commandLine: string): boolean {

‎tests/ci-workflows/ci-workflows.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ describe("GitHub Actions hardening", () => {
828828
};
829829
publish?: {
830830
"runs-on"?: string;
831-
needs?: string;
831+
needs?: string[];
832832
permissions?: Record<string, string>;
833833
};
834834
};
@@ -843,7 +843,9 @@ describe("GitHub Actions hardening", () => {
843843
contents: "read",
844844
});
845845

846-
expect(release.jobs?.publish?.needs).toBe("validate-dispatch");
846+
// Publication is the irreversible public act, so it waits for both packaging jobs;
847+
// the full ordering contract is in tests/ci-workflows/release-pipeline-contract.test.ts.
848+
expect(release.jobs?.publish?.needs).toEqual(["validate-dispatch", "package-standalone", "package-desktop"]);
847849
expect(release.jobs?.publish?.["runs-on"]).toBe("ubuntu-latest");
848850
expect(release.jobs?.publish?.permissions).toEqual({
849851
contents: "write",
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
import { describe, expect, test } from "bun:test";
2+
import { readFileSync, readdirSync } from "node:fs";
3+
import { repoPath } from "../helpers/repo-root";
4+
5+
type WorkflowStep = {
6+
name?: string;
7+
if?: string;
8+
uses?: string;
9+
with?: Record<string, unknown>;
10+
run?: string;
11+
shell?: string;
12+
};
13+
14+
type WorkflowJob = {
15+
needs?: string[];
16+
strategy?: { matrix?: { include?: Array<{ os?: string }> } };
17+
steps?: WorkflowStep[];
18+
};
19+
20+
type Workflow = { jobs?: Record<string, WorkflowJob | undefined> };
21+
22+
function needsOf(job: WorkflowJob | undefined): string[] {
23+
if (job?.needs === undefined) return [];
24+
return typeof job.needs === "string" ? [job.needs] : job.needs;
25+
}
26+
27+
function readWorkflow(...segments: string[]): Workflow {
28+
return Bun.YAML.parse(readFileSync(repoPath(...segments), "utf8")) as Workflow;
29+
}
30+
31+
function triggerPaths(workflowText: string, trigger: string, until: string): string[] {
32+
const afterTrigger = workflowText.split(`${trigger}:`)[1]?.split(`${until}:`)[0];
33+
expect(afterTrigger).toBeDefined();
34+
return afterTrigger!
35+
.split("\n")
36+
.map(line => line.trim())
37+
.filter(line => line.startsWith('- "'))
38+
.map(line => line.slice(3, -1));
39+
}
40+
41+
/**
42+
* Contracts for the release pipeline itself. Each assertion encodes a defect that a green
43+
* workflow can still carry: a bash script silently reinterpreted by PowerShell on a Windows
44+
* runner, a checksum that records a path its verifier cannot resolve, publication that outruns
45+
* packaging, and a service gate that names one file while the implementation is a directory.
46+
*/
47+
describe("release pipeline contract", () => {
48+
const release = readWorkflow(".github", "workflows", "release.yml");
49+
50+
test("every multi-line script on a Windows runner declares an explicit shell", () => {
51+
for (const jobId of ["package-standalone", "package-desktop"]) {
52+
const job = release.jobs?.[jobId];
53+
expect(job, jobId).toBeDefined();
54+
const runsOnWindows = job!.strategy?.matrix?.include?.some(entry => entry.os === "windows-latest");
55+
expect(runsOnWindows, `${jobId} exercises Windows`).toBe(true);
56+
for (const step of job!.steps ?? []) {
57+
// A single command line is shell-neutral; a script block implies shell-specific
58+
// syntax and must not fall back to the runner's default shell on Windows.
59+
if (typeof step.run !== "string" || !step.run.includes("\n")) continue;
60+
// Steps fenced away from Windows never meet PowerShell.
61+
if (/runner\.os\s*==\s*'(Linux|macOS)'/.test(step.if ?? "")) continue;
62+
expect(step.shell, `${jobId} / ${step.name}`).toBeDefined();
63+
}
64+
}
65+
});
66+
67+
test("the release asset rename runs under bash", () => {
68+
const step = release.jobs?.["package-desktop"]?.steps
69+
?.find(candidate => candidate.run?.includes("collect-release-assets.ts"));
70+
expect(step).toBeDefined();
71+
// The script uses backslash continuations and "$VAR" expansion, which PowerShell does
72+
// not read the way bash does; on the Windows matrix this step is only correct under bash.
73+
expect(step!.shell).toBe("bash");
74+
});
75+
76+
test("standalone checksums record bare names that resolve where the verifier runs", () => {
77+
const archive = release.jobs?.["package-standalone"]?.steps
78+
?.find(candidate => candidate.run?.includes("sha256sum"));
79+
expect(archive).toBeDefined();
80+
const checksumLines = archive!.run!.split("\n")
81+
.filter(line => line.includes("sha256sum") && !line.trim().startsWith("#"));
82+
expect(checksumLines.length).toBeGreaterThanOrEqual(2);
83+
for (const line of checksumLines) {
84+
const argument = /sha256sum\s+"([^"]+)"/.exec(line)?.[1];
85+
expect(argument, line).toBeDefined();
86+
// shasum -c resolves the recorded path relative to the verifier's working directory,
87+
// which is dist/release; any directory prefix names a file that cannot exist there.
88+
expect(argument!).not.toContain("/");
89+
// The redirect target gets the same treatment: a bare output name is what makes the
90+
// checksum file land in the directory the upload glob scans.
91+
const output = />\s+"([^"]+)"/.exec(line)?.[1];
92+
expect(output, line).toBeDefined();
93+
expect(output!).not.toContain("/");
94+
}
95+
96+
// The bare names above only resolve end to end if the step checksums from the directory
97+
// the artifact lives in (it leaves the per-target build directory first), if the upload
98+
// glob picks the checksum file up, and if the download flattens every artifact beside
99+
// the verifier. Locking only the final shasum line would leave those joints unguarded.
100+
// YAML block scalars are dedented on parse, so the script's own lines carry no
101+
// indentation here.
102+
expect(archive!.run).toMatch(/^ *cd \.\.\/\.\.$/m);
103+
const upload = release.jobs?.["package-standalone"]?.steps
104+
?.find(candidate => candidate.uses?.startsWith("actions/upload-artifact@"));
105+
expect(String(upload?.with?.path)).toContain("dist/ocx-*.sha256");
106+
107+
const download = release.jobs?.["attach-release"]?.steps
108+
?.find(candidate => candidate.uses?.startsWith("actions/download-artifact@")
109+
&& candidate.with?.pattern === "standalone-*");
110+
expect(download?.with?.["merge-multiple"]).toBe(true);
111+
expect(download?.with?.path).toBe("dist/release");
112+
113+
const verify = release.jobs?.["attach-release"]?.steps
114+
?.find(candidate => candidate.run?.includes("shasum"));
115+
expect(verify).toBeDefined();
116+
expect(verify!.run).toContain("cd dist/release");
117+
expect(verify!.run).toContain("shasum -a 256 -c ./*.sha256");
118+
});
119+
120+
test("publication waits for both packaging jobs", () => {
121+
const publish = release.jobs?.publish;
122+
expect(publish).toBeDefined();
123+
expect(needsOf(publish).sort())
124+
.toEqual(["package-desktop", "package-standalone", "validate-dispatch"]);
125+
126+
const attach = release.jobs?.["attach-release"];
127+
expect(attach).toBeDefined();
128+
expect(needsOf(attach).sort()).toEqual(["package-desktop", "package-standalone", "publish"]);
129+
});
130+
});
131+
132+
describe("service lifecycle trigger coverage", () => {
133+
const lifecycleText = readFileSync(repoPath(".github", "workflows", "service-lifecycle.yml"), "utf8");
134+
const releaseText = readFileSync(repoPath(".github", "workflows", "release.yml"), "utf8");
135+
136+
test("both triggers cover the service directory and the desktop shell", () => {
137+
const pushPaths = triggerPaths(lifecycleText, "push", "workflow_dispatch");
138+
const prPaths = triggerPaths(lifecycleText, "pull_request", "push");
139+
for (const paths of [prPaths, pushPaths]) {
140+
expect(paths).toContain("src/service.ts");
141+
expect(paths).toContain("src/service/**");
142+
expect(paths).toContain("desktop/**");
143+
}
144+
expect([...prPaths].sort()).toEqual([...pushPaths].sort());
145+
});
146+
147+
test("the release service gate matches every implemented service module and desktop file", () => {
148+
const gateSource = releaseText.match(/grep -Eq '(\^\([^']+\)\$)'/)?.[1];
149+
expect(gateSource).toBeDefined();
150+
const gate = new RegExp(gateSource!);
151+
152+
// Derived from the tree, not restated: the service implementation is a directory, so
153+
// every module in it must satisfy the gate that demands lifecycle evidence.
154+
const serviceModules = readdirSync(repoPath("src", "service"))
155+
.filter(entry => entry.endsWith(".ts"));
156+
expect(serviceModules.length).toBeGreaterThanOrEqual(10);
157+
for (const module of serviceModules) {
158+
expect(gate.test(`src/service/${module}`), `src/service/${module}`).toBe(true);
159+
}
160+
expect(gate.test("src/service.ts")).toBe(true);
161+
162+
const desktopSurfaces = [
163+
...readdirSync(repoPath("desktop", "scripts")).map(entry => `desktop/scripts/${entry}`),
164+
...readdirSync(repoPath("desktop", "src-tauri", "src")).map(entry => `desktop/src-tauri/src/${entry}`),
165+
];
166+
expect(desktopSurfaces.length).toBeGreaterThanOrEqual(10);
167+
for (const path of desktopSurfaces) {
168+
expect(gate.test(path), path).toBe(true);
169+
}
170+
171+
expect(gate.test("src/router.ts")).toBe(false);
172+
expect(gate.test("docs-site/src/pages/index.astro")).toBe(false);
173+
});
174+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { describe, expect, test } from "bun:test";
2+
import { readFileSync } from "node:fs";
3+
import { repoPath } from "../helpers/repo-root";
4+
5+
/**
6+
* The desktop shell's management client talks to the loopback proxy with the admin token
7+
* attached. reqwest resolves system proxy configuration by default — HTTP_PROXY,
8+
* HTTPS_PROXY, and the platform proxy settings behind them — so a machine-wide proxy
9+
* would receive a credential that is only ever meant for the loopback endpoint. The builder
10+
* has to opt out explicitly; nothing in the request path re-checks it afterwards.
11+
*/
12+
describe("desktop management transport", () => {
13+
const source = readFileSync(repoPath("desktop", "src-tauri", "src", "proxy.rs"), "utf8");
14+
15+
test("the proxy client disables system proxy resolution for its loopback traffic", () => {
16+
// Line comments are stripped first: a .no_proxy() that only exists in prose must not
17+
// satisfy the contract.
18+
const code = source.replace(/\/\/[^\n]*/g, "");
19+
const builder = code.split("Client::builder()")[1]?.split(".build()")[0];
20+
expect(builder).toBeDefined();
21+
expect(builder).toContain(".no_proxy()");
22+
});
23+
});

‎tests/fixtures/test-layout-expected.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,5 +1468,7 @@
14681468
"ambiguous-resend-gate.test.ts": "lib",
14691469
"docs-developer-role-policy.test.ts": "ci-workflows",
14701470
"ambiguous-resend-composition.test.ts": "lib",
1471-
"chat-inbound-developer-position.test.ts": "responses"
1471+
"chat-inbound-developer-position.test.ts": "responses",
1472+
"release-pipeline-contract.test.ts": "ci-workflows",
1473+
"desktop-proxy-direct-transport.test.ts": "clients"
14721474
}

‎tests/service/process-state.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,23 @@ describe("proxy process-state ownership", () => {
9696
expect(isOcxStartCommandLine("opencodex update --tag latest")).toBe(false);
9797
});
9898

99+
test("recognizes the Windows standalone executable, whatever its case or path shape", () => {
100+
// scripts/build-standalone.ts and desktop/scripts/prepare-sidecar.ts both emit ocx.exe
101+
// on Windows targets, and the bundled sidecar is copied as ocx-<triple>.exe. A quoted
102+
// install path with spaces is the realistic WMIC/PowerShell command line for it.
103+
expect(isOcxCommandLine('"C:/Program Files/OpenCodex/bin/ocx.exe" start --port 10100')).toBe(true);
104+
expect(isOcxCommandLine('"C:\\Program Files\\OpenCodex\\bin\\OCX.EXE" start')).toBe(true);
105+
expect(isOcxCommandLine("C:/tools/ocx.exe stop")).toBe(true);
106+
expect(isOcxCommandLine("ocx.exe")).toBe(true);
107+
expect(isOcxCommandLine("opencodex.exe status")).toBe(true);
108+
expect(isOcxStartCommandLine('"C:/Program Files/OpenCodex/bin/ocx.exe" start')).toBe(true);
109+
// Lookalikes stay foreign: the token boundary around the executable name is the whole
110+
// defence, and widening it for .exe must not widen it for neighbours.
111+
expect(isOcxCommandLine("not-ocx.exe start")).toBe(false);
112+
expect(isOcxCommandLine("myocx.exe")).toBe(false);
113+
expect(isOcxCommandLine("ocx.exes start")).toBe(false);
114+
});
115+
99116
test("the ownership probe distinguishes a real owner from a reused PID", () => {
100117
// The stop-side teardown recovery asks this about a PID recorded in a receipt. Bare
101118
// liveness said "still running" for any process that inherited the number, so the

0 commit comments

Comments
 (0)