Skip to content

Commit 9abb77c

Browse files
fix(pstack): load the bundled pack after test fixtures are pruned (#51)
* fix(pstack): load the bundled pack after test fixtures are pruned Packaged desktop builds delete the statechart test corpus from the bundled pstack resources, but the server still copied every file in UPSTREAM.json, so materializing the pack failed with ENOENT and no /pstack:* skills loaded. The pruned directory is now one exported constant in @t3tools/pstack. pstackPackEntries excludes it from the runtime pack and the desktop build prunes exactly that directory, so a packaged source root is complete by construction. checkPack still verifies the full upstream source. Claude Opus 5.5 via T3 Code Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * test(pstack): pin the pruned corpus to the shared constant The unit test hardcoded the pruned directory, so a typo in PSTACK_PACKAGED_PRUNED_DIR would still pass it. It now derives the fixture paths from the constant, and a new case checks the shipped UPSTREAM.json actually carries files under that prefix so an upstream re-sync that renames the corpus cannot turn the filter into a no-op. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent ef873ed commit 9abb77c

6 files changed

Lines changed: 44 additions & 3 deletions

File tree

‎packages/pstack/src/check.test.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import * as NodePath from "node:path";
55
import * as NodeURL from "node:url";
66
import { describe, expect, it } from "vite-plus/test";
77
import { checkPack } from "./check.ts";
8-
import { fileFingerprint, packFiles, type UpstreamManifest } from "./files.ts";
8+
import { fileFingerprint, packFiles, readManifest, type UpstreamManifest } from "./files.ts";
99
import {
1010
parsePstackRoleDefaults,
1111
pstackContentHash,
1212
pstackPackEntries,
13+
PSTACK_PACKAGED_PRUNED_DIR,
1314
PSTACK_SKILL_PREFIX,
1415
PSTACK_LAYOUT_VERSION,
1516
} from "./index.ts";
@@ -201,6 +202,28 @@ describe("pack interface", () => {
201202
expect(() => pstackPackEntries(pack.root)).not.toThrow();
202203
});
203204

205+
it("delivers a complete pack when packaging pruned the statechart test corpus", () => {
206+
using pack = fixture();
207+
pack.write("upstream/skills/statechart/scripts/statechart.ts", "export {};\n");
208+
pack.write(`upstream/${PSTACK_PACKAGED_PRUNED_DIR}/corpus/Counter/chart.mmd`, "chart\n");
209+
pack.seal();
210+
expect(checkPack(pack.root)).toEqual([]);
211+
NodeFS.rmSync(NodePath.join(pack.root, "upstream", PSTACK_PACKAGED_PRUNED_DIR), {
212+
recursive: true,
213+
});
214+
const entries = pstackPackEntries(pack.root);
215+
expect(entries.map(({ packPath }) => packPath)).toContain(
216+
"skills/statechart/scripts/statechart.ts",
217+
);
218+
expect(entries.filter(({ sourcePath }) => !NodeFS.existsSync(sourcePath))).toEqual([]);
219+
});
220+
221+
it("prunes a corpus the shipped snapshot actually carries", () => {
222+
const pruned = (packPath: string) => packPath.startsWith(`${PSTACK_PACKAGED_PRUNED_DIR}/`);
223+
expect(Object.keys(readManifest(packageDir).files).some(pruned)).toBe(true);
224+
expect(pstackPackEntries(packageDir).some(({ packPath }) => pruned(packPath))).toBe(false);
225+
});
226+
204227
it("invalidates the delivery stamp from the adapter layout", () => {
205228
using pack = fixture();
206229
expect(pstackContentHash(pack.root)).not.toBe(pstackContentHash(pack.root, 2));

‎packages/pstack/src/index.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ export { parsePstackRoleDefaults, PSTACK_PANEL_ROLES, type PstackRoleDefault } f
88
export const PSTACK_SKILL_PREFIX = "pstack:";
99
export const PSTACK_LAYOUT_VERSION = 3;
1010

11-
const isRuntimePackFile = (packPath: string) => NodePath.posix.basename(packPath) !== ".gitignore";
11+
/** Upstream test corpus that packaged desktop builds delete; the runtime pack never needs it. */
12+
export const PSTACK_PACKAGED_PRUNED_DIR = "skills/statechart/scripts/test";
13+
14+
const isRuntimePackFile = (packPath: string) =>
15+
NodePath.posix.basename(packPath) !== ".gitignore" &&
16+
!packPath.startsWith(`${PSTACK_PACKAGED_PRUNED_DIR}/`);
1217

1318
/** Files relative to a source root containing upstream/ and UPSTREAM.json. */
1419
export function pstackPackEntries(sourceRoot: string): ReadonlyArray<{

‎pnpm-lock.yaml‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎scripts/build-desktop-artifact.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import {
7171
ReleasePackageManifestError,
7272
releasePackageFiles,
7373
} from "./update-release-package-versions.ts";
74+
import { pstackPackEntries } from "@t3tools/pstack";
7475
import * as HostProcess from "@t3tools/shared/HostProcess";
7576
import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
7677

@@ -1377,10 +1378,17 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
13771378
path.join(import.meta.dirname, "../packages/pstack/upstream"),
13781379
path.join(packagedPstackDir, "upstream"),
13791380
);
1381+
yield* fs.copy(
1382+
path.join(import.meta.dirname, "../packages/pstack/UPSTREAM.json"),
1383+
path.join(packagedPstackDir, "UPSTREAM.json"),
1384+
);
13801385
yield* prunePackagedPstackTestFixtures(packagedPstackDir);
13811386
const scriptsDir = path.join(packagedPstackDir, "upstream/skills/statechart/scripts");
13821387
assert.isFalse(yield* fs.exists(path.join(scriptsDir, "test")));
13831388
assert.isTrue(yield* fs.exists(path.join(scriptsDir, "statechart.ts")));
1389+
for (const { sourcePath } of pstackPackEntries(packagedPstackDir)) {
1390+
assert.isTrue(yield* fs.exists(sourcePath), sourcePath);
1391+
}
13841392
yield* stageSelfContainedPlatformPackages(
13851393
path.join(import.meta.dirname, "../apps/server/node_modules"),
13861394
path.join(fixture.packagedAppDir, "resources/node_modules"),

‎scripts/build-desktop-artifact.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
type DirectoryRecord,
1717
} from "@electron/asar";
1818

19+
import { PSTACK_PACKAGED_PRUNED_DIR } from "@t3tools/pstack";
1920
import { fromYaml } from "@t3tools/shared/schemaYaml";
2021
import * as HostProcess from "@t3tools/shared/HostProcess";
2122
import { clerkFrontendApiHostnameFromPublishableKey } from "@t3tools/shared/relayAuth";
@@ -3106,7 +3107,7 @@ export const prunePackagedPstackTestFixtures = Effect.fn("prunePackagedPstackTes
31063107
function* (pstackDir: string) {
31073108
const fs = yield* FileSystem.FileSystem;
31083109
const path = yield* Path.Path;
3109-
const fixtureDir = path.join(pstackDir, "upstream/skills/statechart/scripts/test");
3110+
const fixtureDir = path.join(pstackDir, "upstream", PSTACK_PACKAGED_PRUNED_DIR);
31103111
yield* fs.remove(fixtureDir, { recursive: true, force: true });
31113112
},
31123113
);

‎scripts/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@electron/asar": "^4.3.0",
1212
"@electron/osx-sign": "2.7.0",
1313
"@t3tools/contracts": "workspace:*",
14+
"@t3tools/pstack": "workspace:*",
1415
"@t3tools/shared": "workspace:*",
1516
"@t3tools/tailscale": "workspace:*",
1617
"agent-device": "0.21.32",

0 commit comments

Comments
 (0)