Skip to content

Commit 40c0d2a

Browse files
committed
web(look): the build id test hashes what was staged, as the build now does
The merge of feat/web-edition replaced the build's list of inputs with a hash of the staging folder. The test of that list now stages the extensions and hashes the result the same way, and COPY_SKIP — exported only for the list — goes.
1 parent 1d32681 commit 40c0d2a

2 files changed

Lines changed: 11 additions & 21 deletions

File tree

‎web/lib/extensions.mjs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ export function declarativeExtensionNames(extensionsDir, excludeNames = []) {
4444
return names;
4545
}
4646

47-
/** Names `copyExtension` leaves out, for hashing the same inputs it copies. */
48-
export const COPY_SKIP = [...SKIP];
49-
5047
/**
5148
* @param {string} extensionsDir Code-OSS's extensions/ directory
5249
* @param {string} outDir where to stage

‎web/test/unit/extensions.test.js‎

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*---------------------------------------------------------------------------------------------
22
* web/lib/extensions.mjs — run: node web/test/unit/extensions.test.js
33
*
4-
* Which of Code-OSS's extensions the browser edition carries, how they are staged, and what the build id is made
5-
* of for them. The id must see exactly what is staged: a grammar that changed and an id that did not is a stale
4+
* Which of Code-OSS's extensions the browser edition carries, how they are staged, and that the build id changes
5+
* with them. The id must see exactly what is staged: a grammar that changed and an id that did not is a stale
66
* file for a year under an immutable prefix.
77
*--------------------------------------------------------------------------------------------*/
88
// @ts-check
@@ -21,7 +21,7 @@ const write = (root, rel, text) => { const f = path.join(root, rel); fs.mkdirSyn
2121

2222
(async () => {
2323
const lib = path.join(__dirname, '..', '..', 'lib');
24-
const { declarativeExtensionNames, stageDeclarativeExtensions, copyExtension, COPY_SKIP } = await import(pathToFileURL(path.join(lib, 'extensions.mjs')).href);
24+
const { declarativeExtensionNames, stageDeclarativeExtensions } = await import(pathToFileURL(path.join(lib, 'extensions.mjs')).href);
2525
const { hashTree } = await import(pathToFileURL(path.join(lib, 'fingerprint.mjs')).href);
2626

2727
const checkout = () => {
@@ -63,11 +63,14 @@ const write = (root, rel, text) => { const f = path.join(root, rel); fs.mkdirSyn
6363
});
6464

6565
await test('the build id sees a changed grammar, a new extension and a removed one — and not a test file', () => {
66+
// scripts/build-web.mjs names the build after a hash of its staging folder; this stages and hashes the same way.
6667
const d = checkout();
6768
const id = () => {
68-
const h = createHash('sha256');
69-
for (const name of declarativeExtensionNames(d, ['baked'])) { h.update('\0ext\0' + name); hashTree(h, path.join(d, name), { skip: [...COPY_SKIP, '.DS_Store'] }); }
70-
return h.digest('hex');
69+
const out = fs.mkdtempSync(path.join(os.tmpdir(), 'lc-ext-out-'));
70+
try {
71+
stageDeclarativeExtensions(d, out, { exclude: ['baked'] });
72+
return hashTree(createHash('sha256'), out, { skip: ['.DS_Store'] }).digest('hex');
73+
} finally { fs.rmSync(out, { recursive: true, force: true }); }
7174
};
7275
try {
7376
const base = id();
@@ -80,19 +83,9 @@ const write = (root, rel, text) => { const f = path.join(root, rel); fs.mkdirSyn
8083
fs.rmSync(path.join(d, 'extra'), { recursive: true });
8184
assert.strictEqual(id(), changed, 'and back');
8285
write(d, 'json/test/fixture.json', '{"more":1}');
83-
assert.strictEqual(id(), changed, 'a test file is not staged, so it is not part of the build');
84-
} finally { fs.rmSync(d, { recursive: true, force: true }); }
85-
});
86-
87-
await test('what the id skips is what the copy skips', () => {
88-
for (const name of ['node_modules', 'test', 'src', '.git']) { assert.ok(COPY_SKIP.includes(name), name); }
89-
const d = checkout();
90-
const out = fs.mkdtempSync(path.join(os.tmpdir(), 'lc-ext-out-'));
91-
try {
9286
write(d, 'json/node_modules/x/index.js', 'x');
93-
copyExtension(path.join(d, 'json'), path.join(out, 'json'));
94-
assert.ok(!fs.existsSync(path.join(out, 'json', 'node_modules')));
95-
} finally { fs.rmSync(d, { recursive: true, force: true }); fs.rmSync(out, { recursive: true, force: true }); }
87+
assert.strictEqual(id(), changed, 'a test file or a dependency is not staged, so it is not part of the build');
88+
} finally { fs.rmSync(d, { recursive: true, force: true }); }
9689
});
9790

9891
console.log(`\n${n} tests passed`);

0 commit comments

Comments
 (0)