Skip to content

Commit 443e318

Browse files
committed
test(gates): pin both pack-stub directions in the publish check
An undeclared PackStub.swift under Tests/ is a test source the path guard must reject, and a declared stub whose test target left Package.swift is a dead stub the manifest check must name. The membership rule had no test for the first case, and nothing checked the stale direction.
1 parent 4e800b0 commit 443e318

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,34 @@ test('publish package requires both Android helpers and excludes benchmark scrip
8888
),
8989
/macOS helper test sources/,
9090
);
91+
// A stub path under Tests/ that the declared list does not name is a test source, not an
92+
// exemption: the old suffix rule let any PackStub.swift through.
93+
assert.throws(
94+
() =>
95+
assertPublishPackageContents(
96+
[
97+
...fixturePack.files,
98+
{
99+
path: 'apple/macos-helper/Tests/AgentDeviceSneakyTests/PackStub.swift',
100+
size: 1,
101+
},
102+
],
103+
{ macosHelperManifestSource: helperManifestSource },
104+
),
105+
/macOS helper test sources: apple\/macos-helper\/Tests\/AgentDeviceSneakyTests\/PackStub\.swift/,
106+
);
107+
// The other direction: a declared stub whose target left the manifest is a dead stub riding in
108+
// the pack on a stale package.json entry, exempt from the path guard, and must be named.
109+
assert.throws(
110+
() =>
111+
assertPublishPackageContents(fixturePack.files, {
112+
// The manifest now declares only the Input test target; the pack still ships both stubs.
113+
macosHelperManifestSource: ['.testTarget(', ' name: "AgentDeviceMacOSInputTests",'].join(
114+
'\n',
115+
),
116+
}),
117+
/no test target declares: apple\/macos-helper\/Tests\/AgentDeviceMacOSHelperTests\/PackStub\.swift/,
118+
);
91119
// Sources without the manifest are not a buildable Swift package; the pack must say so.
92120
assert.throws(
93121
() =>

‎scripts/size-report-package.mjs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,21 @@ export function assertPublishPackageContents(entries, options = {}) {
141141
.join(', ')}`,
142142
);
143143
}
144+
// The other direction: a declared stub whose target left the manifest stays exempt from the
145+
// path guard above, so compare against the manifest set here. A target removed or renamed
146+
// without retiring its package.json `files` entry and its DOCUMENTED_PACK_STUBS declaration
147+
// would otherwise ship a dead stub forever.
148+
const expectedStubs = new Set(
149+
testTargets.map((target) => `apple/macos-helper/Tests/${target}/PackStub.swift`),
150+
);
151+
const staleStubs = [...documentedStubPaths].filter(
152+
(stubPath) => paths.includes(stubPath) && !expectedStubs.has(stubPath),
153+
);
154+
if (staleStubs.length > 0) {
155+
throw new Error(
156+
`npm pack ships documented pack stubs no test target declares: ${staleStubs.join(', ')}`,
157+
);
158+
}
144159
}
145160
}
146161

0 commit comments

Comments
 (0)