vomebook commited on
Commit
fe286fa
·
1 Parent(s): 0ec0916

Pin search result identity behavior

Browse files
Dockerfile CHANGED
@@ -44,6 +44,7 @@ RUN npx --no-install pyright --project pyrightconfig.json \
44
  && node scripts/check_search_response_validation_coverage.mjs \
45
  && node --test tests/test_search_extension_inventory_baseline.mjs tests/test_search_extension_filter_baseline.mjs \
46
  && node --test tests/test_search_response_validation_baseline.mjs \
 
47
  && printf 'static gate tests passed\n' >/check/static-gate-test-ok
48
 
49
  FROM node:26.11.1-bookworm-slim AS static-assets
 
44
  && node scripts/check_search_response_validation_coverage.mjs \
45
  && node --test tests/test_search_extension_inventory_baseline.mjs tests/test_search_extension_filter_baseline.mjs \
46
  && node --test tests/test_search_response_validation_baseline.mjs \
47
+ && node --test tests/test_search_stable_id_baseline.mjs \
48
  && printf 'static gate tests passed\n' >/check/static-gate-test-ok
49
 
50
  FROM node:26.11.1-bookworm-slim AS static-assets
tests/test_reader_navigation_host.py CHANGED
@@ -62,6 +62,27 @@ process.stdout.write(stripBundledScripts(readFileSync('static/index.html','utf8'
62
  const invalid = isValidSearchResponse({total:1,page:1,page_size:2,results:[]},1,2);
63
  return [desc.writable,desc.enumerable,desc.configurable,changed,restored,deleted,valid,invalid];
64
  }'''), [True, True, False, True, True, False, True, False])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  self.assertEqual(current.evaluate('''() => [ORDERED_EXTENSIONS.length,
66
  ORDERED_EXTENSIONS.indexOf('pdf'), ORDERED_EXTENSIONS.indexOf('PDF'),
67
  getFileIconType('AAC'), getFileIconType('unknown')]'''), [67, 0, -1, 'audio', 'file'])
 
62
  const invalid = isValidSearchResponse({total:1,page:1,page_size:2,results:[]},1,2);
63
  return [desc.writable,desc.enumerable,desc.configurable,changed,restored,deleted,valid,invalid];
64
  }'''), [True, True, False, True, True, False, True, False])
65
+ self.assertEqual(current.evaluate('''() => {
66
+ const original = getResultStableId;
67
+ const originalPath = globalThis.buildRecordRelativePath;
68
+ const desc = Object.getOwnPropertyDescriptor(globalThis, 'getResultStableId');
69
+ const replacement = () => 'replacement';
70
+ let changed, restored, deleted, fallback, received;
71
+ try {
72
+ globalThis.getResultStableId = replacement;
73
+ changed = getResultStableId === replacement;
74
+ globalThis.getResultStableId = original;
75
+ restored = getResultStableId === original;
76
+ deleted = delete globalThis.getResultStableId;
77
+ const record = {Repo:'R'};
78
+ globalThis.buildRecordRelativePath = value => { received = value === record; return 'mock/path'; };
79
+ fallback = getResultStableId(record);
80
+ } finally {
81
+ globalThis.getResultStableId = original;
82
+ globalThis.buildRecordRelativePath = originalPath;
83
+ }
84
+ return [desc.writable,desc.enumerable,desc.configurable,changed,restored,deleted,fallback,received];
85
+ }'''), [True, True, False, True, True, False, 'R\0mock/path', True])
86
  self.assertEqual(current.evaluate('''() => [ORDERED_EXTENSIONS.length,
87
  ORDERED_EXTENSIONS.indexOf('pdf'), ORDERED_EXTENSIONS.indexOf('PDF'),
88
  getFileIconType('AAC'), getFileIconType('unknown')]'''), [67, 0, -1, 'audio', 'file'])
tests/test_search_stable_id_baseline.mjs ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Original host ID function and the existing record-path helper; no production changes.
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import test from 'node:test';
6
+ import vm from 'node:vm';
7
+
8
+ const root = process.cwd();
9
+ const context = vm.createContext({});
10
+ const dependency = path.join(root, 'static/search/record-path.js');
11
+ vm.runInContext(fs.readFileSync(dependency, 'utf8'), context, {filename: dependency});
12
+ const source = fs.readFileSync(path.join(root, 'static/app.js'), 'utf8');
13
+ const match = source.match(/^function getResultStableId\([^]*?^}/m);
14
+ assert.ok(match, 'original getResultStableId must remain inline');
15
+ vm.runInContext(match[0], context);
16
+ const id = context.getResultStableId;
17
+
18
+ test('non-objects are empty while object fallbacks retain exact path spelling', () => {
19
+ for (const value of [undefined, null, false, 0, 1, '', 'abc', Symbol('x'), () => {}]) {
20
+ assert.equal(id(value), '');
21
+ }
22
+ for (const [value, expected] of [
23
+ [{}, '\0'],
24
+ [[], '\0'],
25
+ [{Repo: 'Repo/Case', File: 'hello world', Extension: 'txt', Folder: ['中', 'sub/dir']},
26
+ 'Repo/Case\0中/sub/dir/hello world.txt'],
27
+ [{Repo: 'X', File: 'file.pdf', Extension: 'pdf', Folder: []}, 'X\0file.pdf.pdf'],
28
+ [{Repo: 0, File: 0, Extension: '', Folder: null}, '\0'],
29
+ [{Repo: 'X', File: 'a', Extension: '', Folder: ['', 'tail']}, 'X\0/tail/a']
30
+ ]) assert.equal(id(value), expected);
31
+ });
32
+
33
+ test('truthy Id precedes id and both retain original String conversion', () => {
34
+ for (const [value, expected] of [
35
+ [{Id: 'Upper', id: 'lower'}, 'Upper'],
36
+ [{Id: 0, id: 'lower'}, 'lower'],
37
+ [{Id: false, id: 17}, '17'],
38
+ [{Id: Symbol.for('probe')}, 'Symbol(probe)'],
39
+ [{Id: {toString() { return 'object-id'; }}}, 'object-id'],
40
+ [Object.assign(Object.create({Id: 'inherited'}), {id: 'own'}), 'inherited']
41
+ ]) assert.equal(id(value), expected);
42
+ });
43
+
44
+ test('ID and path getter reads retain their original order and short-circuiting', () => {
45
+ const trace = [];
46
+ const record = {
47
+ get Id() { trace.push('Id'); return ''; },
48
+ get id() { trace.push('id'); return 0; },
49
+ get Repo() { trace.push('Repo'); return 'R'; },
50
+ get File() { trace.push('File'); return 'a'; },
51
+ get Extension() { trace.push('Extension'); return 'txt'; },
52
+ get Folder() { trace.push('Folder'); return ['folder']; }
53
+ };
54
+ assert.equal(id(record), 'R\0folder/a.txt');
55
+ assert.deepEqual(trace, ['Id', 'id', 'Repo', 'File', 'Extension', 'Folder', 'Folder']);
56
+ const seen = [];
57
+ assert.equal(id({get Id() { seen.push('Id'); return 'stable'; },
58
+ get Repo() { throw new Error('Repo must not be read'); }}), 'stable');
59
+ assert.deepEqual(seen, ['Id', 'Id']);
60
+ });
61
+
62
+ test('dependency lookup and exceptional values propagate unchanged', () => {
63
+ assert.throws(() => id({get Id() { throw new Error('id getter'); }}), {message: 'id getter'});
64
+ assert.throws(() => id({Repo: Symbol('repo')}), {name: 'TypeError'});
65
+ const original = context.buildRecordRelativePath;
66
+ const record = {Repo: 'R'};
67
+ context.buildRecordRelativePath = value => { assert.equal(value, record); return 'mock/path'; };
68
+ assert.equal(id(record), 'R\0mock/path');
69
+ context.buildRecordRelativePath = () => { throw new Error('path helper'); };
70
+ assert.throws(() => id(record), {message: 'path helper'});
71
+ context.buildRecordRelativePath = original;
72
+ });
tests/test_static_contract.py CHANGED
@@ -451,6 +451,7 @@ class StaticFrontendContractTests(unittest.TestCase):
451
  self.assertIn("node scripts/check_search_file_types_coverage.mjs", dockerfile)
452
  self.assertIn("node scripts/check_search_response_validation_coverage.mjs", dockerfile)
453
  self.assertIn("node --test tests/test_search_response_validation_baseline.mjs", dockerfile)
 
454
  self.assertIn("COPY --from=source-check-node /check/ /check/", dockerfile)
455
  self.assertIn("COPY --from=source-check-python /usr/local/lib/python3.11/site-packages/ /tmp/python-static-tools/", dockerfile)
456
  self.assertIn("COPY --from=source-check-python /usr/local/bin/ruff /tmp/python-static-tools/bin/ruff", dockerfile)
 
451
  self.assertIn("node scripts/check_search_file_types_coverage.mjs", dockerfile)
452
  self.assertIn("node scripts/check_search_response_validation_coverage.mjs", dockerfile)
453
  self.assertIn("node --test tests/test_search_response_validation_baseline.mjs", dockerfile)
454
+ self.assertIn("node --test tests/test_search_stable_id_baseline.mjs", dockerfile)
455
  self.assertIn("COPY --from=source-check-node /check/ /check/", dockerfile)
456
  self.assertIn("COPY --from=source-check-python /usr/local/lib/python3.11/site-packages/ /tmp/python-static-tools/", dockerfile)
457
  self.assertIn("COPY --from=source-check-python /usr/local/bin/ruff /tmp/python-static-tools/bin/ruff", dockerfile)