vomebook commited on
Commit ·
fe286fa
1
Parent(s): 0ec0916
Pin search result identity behavior
Browse filesFiles changed (4)
43 unmodified lines44454647484943 unmodified lines&& node scripts/check_search_response_validation_coverage.mjs \&& node --test tests/test_search_extension_inventory_baseline.mjs tests/test_search_extension_filter_baseline.mjs \&& node --test tests/test_search_response_validation_baseline.mjs \&& printf 'static gate tests passed\n' >/check/static-gate-test-okFROM node:26.11.1-bookworm-slim AS static-assets43 unmodified lines4445464748495043 unmodified lines&& node scripts/check_search_response_validation_coverage.mjs \&& node --test tests/test_search_extension_inventory_baseline.mjs tests/test_search_extension_filter_baseline.mjs \&& node --test tests/test_search_response_validation_baseline.mjs \&& node --test tests/test_search_stable_id_baseline.mjs \&& printf 'static gate tests passed\n' >/check/static-gate-test-okFROM node:26.11.1-bookworm-slim AS static-assets
61 unmodified lines62636465666761 unmodified linesconst invalid = isValidSearchResponse({total:1,page:1,page_size:2,results:[]},1,2);return [desc.writable,desc.enumerable,desc.configurable,changed,restored,deleted,valid,invalid];}'''), [True, True, False, True, True, False, True, False])self.assertEqual(current.evaluate('''() => [ORDERED_EXTENSIONS.length,ORDERED_EXTENSIONS.indexOf('pdf'), ORDERED_EXTENSIONS.indexOf('PDF'),getFileIconType('AAC'), getFileIconType('unknown')]'''), [67, 0, -1, 'audio', 'file'])61 unmodified lines62636465666768697071727374757677787980818283848586878861 unmodified linesconst invalid = isValidSearchResponse({total:1,page:1,page_size:2,results:[]},1,2);return [desc.writable,desc.enumerable,desc.configurable,changed,restored,deleted,valid,invalid];}'''), [True, True, False, True, True, False, True, False])self.assertEqual(current.evaluate('''() => {const original = getResultStableId;const originalPath = globalThis.buildRecordRelativePath;const desc = Object.getOwnPropertyDescriptor(globalThis, 'getResultStableId');const replacement = () => 'replacement';let changed, restored, deleted, fallback, received;try {globalThis.getResultStableId = replacement;changed = getResultStableId === replacement;globalThis.getResultStableId = original;restored = getResultStableId === original;deleted = delete globalThis.getResultStableId;const record = {Repo:'R'};globalThis.buildRecordRelativePath = value => { received = value === record; return 'mock/path'; };fallback = getResultStableId(record);} finally {globalThis.getResultStableId = original;globalThis.buildRecordRelativePath = originalPath;}return [desc.writable,desc.enumerable,desc.configurable,changed,restored,deleted,fallback,received];}'''), [True, True, False, True, True, False, 'R\0mock/path', True])self.assertEqual(current.evaluate('''() => [ORDERED_EXTENSIONS.length,ORDERED_EXTENSIONS.indexOf('pdf'), ORDERED_EXTENSIONS.indexOf('PDF'),getFileIconType('AAC'), getFileIconType('unknown')]'''), [67, 0, -1, 'audio', 'file'])
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172// Original host ID function and the existing record-path helper; no production changes.import assert from 'node:assert/strict';import fs from 'node:fs';import path from 'node:path';import test from 'node:test';import vm from 'node:vm';
const root = process.cwd();const context = vm.createContext({});const dependency = path.join(root, 'static/search/record-path.js');vm.runInContext(fs.readFileSync(dependency, 'utf8'), context, {filename: dependency});const source = fs.readFileSync(path.join(root, 'static/app.js'), 'utf8');const match = source.match(/^function getResultStableId\([^]*?^}/m);assert.ok(match, 'original getResultStableId must remain inline');vm.runInContext(match[0], context);const id = context.getResultStableId;
test('non-objects are empty while object fallbacks retain exact path spelling', () => { for (const value of [undefined, null, false, 0, 1, '', 'abc', Symbol('x'), () => {}]) { assert.equal(id(value), ''); } for (const [value, expected] of [ [{}, '\0'], [[], '\0'], [{Repo: 'Repo/Case', File: 'hello world', Extension: 'txt', Folder: ['中', 'sub/dir']}, 'Repo/Case\0中/sub/dir/hello world.txt'], [{Repo: 'X', File: 'file.pdf', Extension: 'pdf', Folder: []}, 'X\0file.pdf.pdf'], [{Repo: 0, File: 0, Extension: '', Folder: null}, '\0'], [{Repo: 'X', File: 'a', Extension: '', Folder: ['', 'tail']}, 'X\0/tail/a'] ]) assert.equal(id(value), expected);});
test('truthy Id precedes id and both retain original String conversion', () => { for (const [value, expected] of [ [{Id: 'Upper', id: 'lower'}, 'Upper'], [{Id: 0, id: 'lower'}, 'lower'], [{Id: false, id: 17}, '17'], [{Id: Symbol.for('probe')}, 'Symbol(probe)'], [{Id: {toString() { return 'object-id'; }}}, 'object-id'], [Object.assign(Object.create({Id: 'inherited'}), {id: 'own'}), 'inherited'] ]) assert.equal(id(value), expected);});
test('ID and path getter reads retain their original order and short-circuiting', () => { const trace = []; const record = { get Id() { trace.push('Id'); return ''; }, get id() { trace.push('id'); return 0; }, get Repo() { trace.push('Repo'); return 'R'; }, get File() { trace.push('File'); return 'a'; }, get Extension() { trace.push('Extension'); return 'txt'; }, get Folder() { trace.push('Folder'); return ['folder']; } }; assert.equal(id(record), 'R\0folder/a.txt'); assert.deepEqual(trace, ['Id', 'id', 'Repo', 'File', 'Extension', 'Folder', 'Folder']); const seen = []; assert.equal(id({get Id() { seen.push('Id'); return 'stable'; }, get Repo() { throw new Error('Repo must not be read'); }}), 'stable'); assert.deepEqual(seen, ['Id', 'Id']);});
test('dependency lookup and exceptional values propagate unchanged', () => { assert.throws(() => id({get Id() { throw new Error('id getter'); }}), {message: 'id getter'}); assert.throws(() => id({Repo: Symbol('repo')}), {name: 'TypeError'}); const original = context.buildRecordRelativePath; const record = {Repo: 'R'}; context.buildRecordRelativePath = value => { assert.equal(value, record); return 'mock/path'; }; assert.equal(id(record), 'R\0mock/path'); context.buildRecordRelativePath = () => { throw new Error('path helper'); }; assert.throws(() => id(record), {message: 'path helper'}); context.buildRecordRelativePath = original;});450 unmodified lines451452453454455456450 unmodified linesself.assertIn("node scripts/check_search_file_types_coverage.mjs", dockerfile)self.assertIn("node scripts/check_search_response_validation_coverage.mjs", dockerfile)self.assertIn("node --test tests/test_search_response_validation_baseline.mjs", dockerfile)self.assertIn("COPY --from=source-check-node /check/ /check/", dockerfile)self.assertIn("COPY --from=source-check-python /usr/local/lib/python3.11/site-packages/ /tmp/python-static-tools/", dockerfile)self.assertIn("COPY --from=source-check-python /usr/local/bin/ruff /tmp/python-static-tools/bin/ruff", dockerfile)450 unmodified lines451452453454455456457450 unmodified linesself.assertIn("node scripts/check_search_file_types_coverage.mjs", dockerfile)self.assertIn("node scripts/check_search_response_validation_coverage.mjs", dockerfile)self.assertIn("node --test tests/test_search_response_validation_baseline.mjs", dockerfile)self.assertIn("node --test tests/test_search_stable_id_baseline.mjs", dockerfile)self.assertIn("COPY --from=source-check-node /check/ /check/", dockerfile)self.assertIn("COPY --from=source-check-python /usr/local/lib/python3.11/site-packages/ /tmp/python-static-tools/", dockerfile)self.assertIn("COPY --from=source-check-python /usr/local/bin/ruff /tmp/python-static-tools/bin/ruff", dockerfile)
Dockerfile+1
tests/test_reader_navigation_host.py+21
tests/test_search_stable_id_baseline.mjsAdded+72
tests/test_static_contract.py+1