Skip to content

Commit 50ae4e5

Browse files
committed
chore(gates): reject missing pinned package entries
1 parent 789709f commit 50ae4e5

2 files changed

Lines changed: 32 additions & 8 deletions

File tree

‎scripts/layering/package-entry-surface.test.ts‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,15 @@ test('the entry names its exports: export * is refused', () => {
106106
"export type * from './a.ts';",
107107
"export { a } from './a.ts';\nexport type * as ns from './b.ts';",
108108
]) {
109-
const found = check({}, new Map([['packages/test-kit/src/index.ts', body]]));
109+
const found = check({}, new Map([...SOURCE, ['packages/test-kit/src/index.ts', body]]));
110110
assert.equal(found.length, 1, body);
111111
assert.match(found[0]!.message, /names every export explicitly/);
112112
}
113113
assert.deepEqual(
114-
check({}, new Map([['packages/test-kit/src/index.ts', "export { a } from './a.ts';"]])),
114+
check(
115+
{},
116+
new Map([...SOURCE, ['packages/test-kit/src/index.ts', "export { a } from './a.ts';"]]),
117+
),
115118
[],
116119
);
117120
});
@@ -120,7 +123,7 @@ test('text that only mentions a star is not an export', () => {
120123
const body =
121124
"// export * from './a.ts' is forbidden here\n" +
122125
"const note = `export * from './b.ts'`;\nexport { note };\nexport { a } from './a.ts';";
123-
assert.deepEqual(check({}, new Map([['packages/test-kit/src/index.ts', body]])), []);
126+
assert.deepEqual(check({}, new Map([...SOURCE, ['packages/test-kit/src/index.ts', body]])), []);
124127
});
125128

126129
test('the daemon entry names its exports: export * is refused', () => {
@@ -154,3 +157,18 @@ test('the shared isolation walk runs under the test-kit policy', () => {
154157
assert.equal(found.length, 1);
155158
assert.match(found[0]!.message, /test-kit -> @agent-device\/daemon/);
156159
});
160+
161+
for (const dir of ['daemon', 'test-kit']) {
162+
test(`${dir} refuses a missing or renamed entry source`, () => {
163+
for (const renamed of [false, true]) {
164+
const sources = new Map(SOURCE);
165+
const file = `packages/${dir}/src/index.ts`;
166+
sources.delete(file);
167+
if (renamed) sources.set(`packages/${dir}/src/renamed.ts`, "export * from './a.ts';");
168+
const found = check({}, sources);
169+
assert.equal(found.length, 1);
170+
assert.equal(found[0]!.file, file);
171+
assert.match(found[0]!.message, /entry source is missing/);
172+
}
173+
});
174+
}

‎scripts/layering/package-entry-surface.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ import {
2424
} from './package-isolation.ts';
2525

2626
const TEST_KIT_DIR = TEST_KIT_ISOLATION.dir;
27-
const TEST_KIT_ENTRY = './src/index.ts';
27+
const ENTRY_FILE = './src/index.ts';
2828
const DAEMON_DIR = 'packages/daemon';
2929
const DAEMON_PACKAGE = '@agent-device/daemon';
3030

3131
const ENTRY_SURFACES = [
32-
{ packageName: TEST_KIT_PACKAGE, dir: TEST_KIT_DIR, entry: TEST_KIT_ENTRY },
33-
{ packageName: DAEMON_PACKAGE, dir: DAEMON_DIR, entry: './src/index.ts' },
32+
{ packageName: TEST_KIT_PACKAGE, dir: TEST_KIT_DIR, entry: ENTRY_FILE },
33+
{ packageName: DAEMON_PACKAGE, dir: DAEMON_DIR, entry: ENTRY_FILE },
3434
] as const;
3535

3636
function stringLeaves(value: unknown): string[] {
@@ -87,9 +87,15 @@ function checkEntrySurface(
8787
);
8888
}
8989

90-
const entryFile = `${entrySurface.dir}/src/index.ts`;
90+
const entryFile = `${entrySurface.dir}/${entrySurface.entry.slice(2)}`;
9191
const entrySource = sources.get(entryFile);
92-
const starLine = entrySource === undefined ? null : findStarExportLine(entryFile, entrySource);
92+
if (entrySource === undefined) {
93+
violations.push(
94+
violation(entryFile, `${entrySurface.packageName} entry source is missing: ${entryFile}.`),
95+
);
96+
return violations;
97+
}
98+
const starLine = findStarExportLine(entryFile, entrySource);
9399
if (starLine !== null) {
94100
violations.push(
95101
violation(

0 commit comments

Comments
 (0)