Skip to content

Commit 41cc8df

Browse files
kriszypclaude
andcommitted
test: cover the global storage.randomAccessFields path in OpenDBIObject
The directive-based tests stamp randomAccessStructure in databases.ts before the store opens, bypassing the OpenDBIObject constructor's global-config branch. Add a focused test that opens a primary/non-primary DBI without a directive and asserts the constructor reads storage.randomAccessFields correctly (true -> on, false -> off, non-primary -> off). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 36b2f28 commit 41cc8df

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require('../../testUtils');
2+
const assert = require('assert');
3+
const { OpenDBIObject } = require('#src/utility/lmdb/OpenDBIObject');
4+
const envMngr = require('#src/utility/environment/environmentManager');
5+
const { CONFIG_PARAMS } = require('#src/utility/hdbTerms');
6+
7+
// Covers the global storage.randomAccessFields path in the OpenDBIObject constructor. The directive
8+
// tests (databases.test.js / randomAccessFieldsDirective.test.js) stamp dbiInit.randomAccessStructure
9+
// in databases.ts before the store opens, bypassing this constructor branch — so a wrong config key,
10+
// a non-boolean value, or a hdbTerms/YAML name mismatch would go uncaught. These open a DBI WITHOUT a
11+
// directive and assert the constructor reads the global config correctly.
12+
describe('OpenDBIObject storage.randomAccessFields global config', () => {
13+
let previous;
14+
beforeEach(() => {
15+
previous = envMngr.get(CONFIG_PARAMS.STORAGE_RANDOMACCESSFIELDS);
16+
});
17+
afterEach(() => {
18+
envMngr.setProperty(CONFIG_PARAMS.STORAGE_RANDOMACCESSFIELDS, previous);
19+
});
20+
21+
it('enables randomAccessStructure on a primary DBI when the global config is true', () => {
22+
envMngr.setProperty(CONFIG_PARAMS.STORAGE_RANDOMACCESSFIELDS, true);
23+
assert.strictEqual(new OpenDBIObject(false, true).randomAccessStructure, true);
24+
});
25+
26+
it('leaves randomAccessStructure off on a primary DBI when the global config is false (default)', () => {
27+
envMngr.setProperty(CONFIG_PARAMS.STORAGE_RANDOMACCESSFIELDS, false);
28+
assert.strictEqual(new OpenDBIObject(false, true).randomAccessStructure, false);
29+
});
30+
31+
it('keeps randomAccessStructure off on non-primary DBIs even when the global config is true', () => {
32+
// Non-primary stores (e.g. the __dbis__ metadata DBI) must stay in records mode for v4-downgrade
33+
// decodability, regardless of the global setting.
34+
envMngr.setProperty(CONFIG_PARAMS.STORAGE_RANDOMACCESSFIELDS, true);
35+
assert.strictEqual(new OpenDBIObject(false, false).randomAccessStructure, false);
36+
});
37+
});

0 commit comments

Comments
 (0)