Skip to content

Commit 563d35e

Browse files
committed
fix(gates): require the helper manifest beside its shipped sources and run npm cross-platform
The pack guard warned in a comment that a manifest-less helper pack is unbuildable but only checked the stub set, so a dropped files entry that ships Sources without Package.swift passed. Require the manifest whenever any apple/macos-helper/Sources entry is packed, and let the fixture pack stand in for a real helper pack (manifest, sources, stubs) so both the missing-manifest and missing-stub failures are covered. The repo guard ran npm through execFileSync, which dies on ENOENT for npm.cmd on Windows; runCmdSync resolves PATH extensions there, as installed-package-metro does. Closes both review threads on 650f9b0.
1 parent 650f9b0 commit 563d35e

4 files changed

Lines changed: 145 additions & 66 deletions

File tree

Lines changed: 79 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,83 @@
11
{
22
"unpackedSize": 2319,
33
"files": [
4-
{ "path": "dist/src/index.js", "size": 401 },
5-
{ "path": "dist/src/index.d.ts", "size": 102 },
6-
{ "path": "dist/apple/runner/RunnerTests.swift", "size": 503 },
7-
{ "path": "dist/apple/snapshot-presentation/Package.swift", "size": 113 },
8-
{ "path": "apple/snapshot-bridge/SnapshotBridge.m", "size": 0 },
9-
{ "path": "apple/snapshot-bridge/SnapshotBridgeRuntime.m", "size": 0 },
10-
{ "path": "apple/snapshot-bridge/SnapshotBridgeRuntime.h", "size": 0 },
11-
{ "path": "apple/snapshot-bridge/SnapshotBridgeCapture.h", "size": 0 },
12-
{ "path": "apple/snapshot-bridge/SnapshotBridgeCapture.m", "size": 0 },
13-
{ "path": "apple/macos-helper/Sources/main.swift", "size": 211 },
14-
{ "path": "android/snapshot-helper/dist/helper.apk", "size": 307 },
15-
{ "path": "android/snapshot-helper/dist/helper.manifest.json", "size": 99 },
16-
{ "path": "android/ime-helper/dist/helper.apk", "size": 307 },
17-
{ "path": "android/ime-helper/dist/helper.manifest.json", "size": 99 },
18-
{ "path": "package.json", "size": 99 },
19-
{ "path": "vendor/unknown.bin", "size": 78 }
20-
]
4+
{
5+
"path": "dist/src/index.js",
6+
"size": 401
7+
},
8+
{
9+
"path": "dist/src/index.d.ts",
10+
"size": 102
11+
},
12+
{
13+
"path": "dist/apple/runner/RunnerTests.swift",
14+
"size": 503
15+
},
16+
{
17+
"path": "dist/apple/snapshot-presentation/Package.swift",
18+
"size": 113
19+
},
20+
{
21+
"path": "apple/snapshot-bridge/SnapshotBridge.m",
22+
"size": 0
23+
},
24+
{
25+
"path": "apple/snapshot-bridge/SnapshotBridgeRuntime.m",
26+
"size": 0
27+
},
28+
{
29+
"path": "apple/snapshot-bridge/SnapshotBridgeRuntime.h",
30+
"size": 0
31+
},
32+
{
33+
"path": "apple/snapshot-bridge/SnapshotBridgeCapture.h",
34+
"size": 0
35+
},
36+
{
37+
"path": "apple/snapshot-bridge/SnapshotBridgeCapture.m",
38+
"size": 0
39+
},
40+
{
41+
"path": "apple/macos-helper/Package.swift",
42+
"size": 1057
43+
},
44+
{
45+
"path": "apple/macos-helper/Sources/main.swift",
46+
"size": 211
47+
},
48+
{
49+
"path": "android/snapshot-helper/dist/helper.apk",
50+
"size": 307
51+
},
52+
{
53+
"path": "android/snapshot-helper/dist/helper.manifest.json",
54+
"size": 99
55+
},
56+
{
57+
"path": "android/ime-helper/dist/helper.apk",
58+
"size": 307
59+
},
60+
{
61+
"path": "android/ime-helper/dist/helper.manifest.json",
62+
"size": 99
63+
},
64+
{
65+
"path": "package.json",
66+
"size": 99
67+
},
68+
{
69+
"path": "vendor/unknown.bin",
70+
"size": 78
71+
},
72+
{
73+
"path": "apple/macos-helper/Tests/AgentDeviceMacOSHelperTests/PackStub.swift",
74+
"size": 426
75+
},
76+
{
77+
"path": "apple/macos-helper/Tests/AgentDeviceMacOSInputTests/PackStub.swift",
78+
"size": 426
79+
}
80+
],
81+
"entryCount": 19,
82+
"size": 3376
2183
}

‎scripts/__tests__/size-report-package.test.ts‎

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,31 @@ const fixturePack = JSON.parse(
99
await readFile(join(import.meta.dirname, 'fixtures', 'size-report-npm-pack.json'), 'utf8'),
1010
);
1111

12+
// The fixture pack ships the macOS helper (manifest, sources, and per-target PackStub.swift),
13+
// so every assertion here names the manifest source the guard would read from the packed tree;
14+
// without it the guard falls back to this checkout's manifest via repoRoot.
15+
const helperManifestSource = [
16+
'.target(',
17+
' name: "AgentDeviceMacOSInput",',
18+
'.executableTarget(',
19+
' name: "AgentDeviceMacOSHelper",',
20+
'.testTarget(',
21+
' name: "AgentDeviceMacOSHelperTests",',
22+
'.testTarget(',
23+
' name: "AgentDeviceMacOSInputTests",',
24+
].join('\n');
25+
1226
test('publish package requires both Android helpers and excludes benchmark scripts', () => {
13-
assert.doesNotThrow(() => assertPublishPackageContents(fixturePack.files));
27+
assert.doesNotThrow(() =>
28+
assertPublishPackageContents(fixturePack.files, {
29+
macosHelperManifestSource: helperManifestSource,
30+
}),
31+
);
1432
assert.throws(
1533
() =>
1634
assertPublishPackageContents(
1735
fixturePack.files.filter((entry) => !entry.path.startsWith('android/ime-helper/')),
36+
{ macosHelperManifestSource: helperManifestSource },
1837
),
1938
/android\/ime-helper/,
2039
);
@@ -31,62 +50,52 @@ test('publish package requires both Android helpers and excludes benchmark scrip
3150
assert.doesNotThrow(() =>
3251
assertPublishPackageContents(
3352
fixturePack.files.filter((entry) => !entry.path.startsWith('apple/snapshot-bridge/')),
53+
{ macosHelperManifestSource: helperManifestSource },
3454
),
3555
);
3656
assert.throws(
3757
() =>
38-
assertPublishPackageContents([
39-
...fixturePack.files,
40-
{ path: 'scripts/ios-snapshot-benchmark/run.ts', size: 1 },
41-
]),
58+
assertPublishPackageContents(
59+
[...fixturePack.files, { path: 'scripts/ios-snapshot-benchmark/run.ts', size: 1 }],
60+
{ macosHelperManifestSource: helperManifestSource },
61+
),
4262
/benchmark or build scripts/,
4363
);
44-
// The helper ships as buildable source, so the manifest in the pack and the per-target
45-
// PackStub.swift set must agree; the fixture carries both sides of that contract.
46-
const helperManifest = { path: 'apple/macos-helper/Package.swift', size: 1 };
47-
const helperStubs = [
48-
{
49-
path: 'apple/macos-helper/Tests/AgentDeviceMacOSHelperTests/PackStub.swift',
50-
size: 1,
51-
},
52-
{
53-
path: 'apple/macos-helper/Tests/AgentDeviceMacOSInputTests/PackStub.swift',
54-
size: 1,
55-
},
56-
];
57-
const helperManifestSource = [
58-
'.target(',
59-
' name: "AgentDeviceMacOSInput",',
60-
'.executableTarget(',
61-
' name: "AgentDeviceMacOSHelper",',
62-
'.testTarget(',
63-
' name: "AgentDeviceMacOSHelperTests",',
64-
'.testTarget(',
65-
' name: "AgentDeviceMacOSInputTests",',
66-
].join('\n');
67-
assert.doesNotThrow(() =>
68-
assertPublishPackageContents([...fixturePack.files, helperManifest, ...helperStubs], {
69-
macosHelperManifestSource: helperManifestSource,
70-
}),
71-
);
64+
// Each declared test target needs its PackStub.swift or the install-time `swift build` of the
65+
// packed tree dies; a missing one must name the missing path.
7266
assert.throws(
7367
() =>
74-
assertPublishPackageContents([...fixturePack.files, helperManifest, helperStubs[0]!], {
75-
macosHelperManifestSource: helperManifestSource,
76-
}),
68+
assertPublishPackageContents(
69+
fixturePack.files.filter(
70+
(entry) =>
71+
entry.path !== 'apple/macos-helper/Tests/AgentDeviceMacOSInputTests/PackStub.swift',
72+
),
73+
{ macosHelperManifestSource: helperManifestSource },
74+
),
7775
/pack stubs: apple\/macos-helper\/Tests\/AgentDeviceMacOSInputTests\/PackStub\.swift/,
7876
);
7977
assert.throws(
8078
() =>
81-
assertPublishPackageContents([
82-
...fixturePack.files,
83-
{
84-
path: 'apple/macos-helper/Tests/AgentDeviceMacOSInputTests/ScheduleTests.swift',
85-
size: 1,
86-
},
87-
]),
79+
assertPublishPackageContents(
80+
[
81+
...fixturePack.files,
82+
{
83+
path: 'apple/macos-helper/Tests/AgentDeviceMacOSInputTests/ScheduleTests.swift',
84+
size: 1,
85+
},
86+
],
87+
{ macosHelperManifestSource: helperManifestSource },
88+
),
8889
/macOS helper test sources/,
8990
);
91+
// Sources without the manifest are not a buildable Swift package; the pack must say so.
92+
assert.throws(
93+
() =>
94+
assertPublishPackageContents(
95+
fixturePack.files.filter((entry) => entry.path !== 'apple/macos-helper/Package.swift'),
96+
),
97+
/sources without its Package\.swift/,
98+
);
9099
});
91100

92101
test('Markdown emphasizes total install size and startup without duplicate breakdowns', () => {

‎scripts/size-report-package.mjs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,15 @@ export function assertPublishPackageContents(entries, options = {}) {
101101
if (shippedSwiftTests.length > 0) {
102102
throw new Error(`npm pack includes macOS helper test sources: ${shippedSwiftTests.join(', ')}`);
103103
}
104-
// Read the target list from the same manifest the pack ships, so the pack and the manifest can
105-
// never drift onto different target sets. A pack without the manifest ships no helper at all.
104+
// Helper sources without the manifest are not a buildable Swift package, so a dropped
105+
// `files` entry that ships Sources but not Package.swift must fail here, not on the user's
106+
// machine. With the manifest present, read the target list from it — the pack and the
107+
// manifest can then never drift onto different target sets.
108+
if (paths.some((entryPath) => entryPath.startsWith('apple/macos-helper/Sources/'))) {
109+
if (!paths.includes('apple/macos-helper/Package.swift')) {
110+
throw new Error('npm pack ships macOS helper sources without its Package.swift');
111+
}
112+
}
106113
if (paths.includes('apple/macos-helper/Package.swift')) {
107114
const manifestSource =
108115
options.macosHelperManifestSource ??

‎test/repo-guards/macos-helper-package-contents.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import assert from 'node:assert/strict';
2-
import { execFileSync } from 'node:child_process';
32
import fs from 'node:fs';
43
import path from 'node:path';
54
import { fileURLToPath } from 'node:url';
5+
import { runCmdSync } from '@agent-device/host-kit/command';
66
import { test } from 'vitest';
77
import { readMacosHelperTestTargets } from '../../scripts/size-report-package.mjs';
88

@@ -30,12 +30,13 @@ function declaredTargetNames(manifest: string, kind: 'target' | 'executableTarge
3030
}
3131

3232
function packedPaths(): string[] {
33-
const stdout = execFileSync('npm', ['pack', '--dry-run', '--json', '--ignore-scripts'], {
33+
// runCmdSync resolves `npm` through the PATH extensions a Windows checkout needs; a bare
34+
// execFileSync('npm', ...) there dies on ENOENT for npm.cmd.
35+
const result = runCmdSync('npm', ['pack', '--dry-run', '--json', '--ignore-scripts'], {
3436
cwd: repoRoot,
35-
encoding: 'utf8',
3637
maxBuffer: 64 * 1024 * 1024,
3738
});
38-
const parsed = JSON.parse(stdout);
39+
const parsed = JSON.parse(result.stdout);
3940
const pack: { files?: { path?: unknown }[] } = Array.isArray(parsed) ? parsed[0] : parsed;
4041
return pack.files?.map((entry) => String(entry.path)) ?? [];
4142
}

0 commit comments

Comments
 (0)