Skip to content

Commit 307a399

Browse files
author
Forge
committed
test(release): inject read failures at the bounded descriptor boundary
1 parent bf81c39 commit 307a399

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

‎__tests__/git-index-currency.test.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
22
import * as cp from 'child_process';
3-
import * as fs from 'fs';
3+
import * as fs from 'node:fs';
44
import * as os from 'os';
55
import * as path from 'path';
66
import { CodeGraph } from '../src';
@@ -11,9 +11,9 @@ vi.mock('child_process', async importOriginal => {
1111
const actual = await importOriginal<typeof import('child_process')>();
1212
return { ...actual, execFileSync: vi.fn(actual.execFileSync) };
1313
});
14-
vi.mock('fs', async importOriginal => {
15-
const actual = await importOriginal<typeof import('fs')>();
16-
return { ...actual, readFileSync: vi.fn(actual.readFileSync) };
14+
vi.mock('node:fs', async importOriginal => {
15+
const actual = await importOriginal<typeof import('node:fs')>();
16+
return { ...actual, readFileSync: vi.fn(actual.readFileSync), openSync: vi.fn(actual.openSync) };
1717
});
1818

1919
describe('git index currency across commits and restores (#1829)', () => {
@@ -132,12 +132,12 @@ describe('git index currency across commits and restores (#1829)', () => {
132132

133133
it('keeps a committed path pending when sync cannot read it', async () => {
134134
write('new.ts', 'newSymbol'); commit();
135-
const real = fs.readFileSync;
135+
const real = fs.openSync;
136136
let injected = 0;
137-
vi.spyOn(fs, 'readFileSync').mockImplementation(((file: any, ...args: any[]) => {
137+
vi.spyOn(fs, 'openSync').mockImplementation(((file: any, ...args: any[]) => {
138138
if (String(file) === path.join(root, 'new.ts')) { injected++; throw new Error('Injected transient read error'); }
139139
return (real as any)(file, ...args);
140-
}) as typeof fs.readFileSync);
140+
}) as typeof fs.openSync);
141141
await cg.sync();
142142
expect(injected).toBeGreaterThan(0);
143143
expect(symbols('newSymbol')).not.toContain('newSymbol');

‎docs/validation/release-linux-shards.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
files=sorted(str(p.relative_to(root)) for p in (root/'__tests__').rglob('*.test.ts'))
77
manifest={'revision':expected,'files':files,'commands':[]}
88
(out/'manifest.json').write_text(json.dumps(manifest,indent=2)+'\n')
9+
failures=[]
910
for shard in range(1,5):
1011
name=f'release-final-shard-{shard}'
1112
if (root/'.qa/recovery'/f'{name}.json').exists():
@@ -15,13 +16,15 @@
1516
assert subprocess.check_output(['git','rev-parse','HEAD'],cwd=root,text=True).strip()==expected
1617
command=['node','node_modules/vitest/vitest.mjs','run',f'--shard={shard}/4','--maxWorkers=1','--minWorkers=1','--reporter=default','--reporter=json',f'--outputFile.json=.qa/release-full/shard-{shard}.json']
1718
result=subprocess.run(['python3','docs/validation/release-command.py',name,*command],cwd=root)
18-
if result.returncode:sys.exit(result.returncode)
19+
if result.returncode:failures.append(shard)
1920
seen=[];counts={'passed':0,'failed':0,'pending':0}
2021
for shard in range(1,5):
2122
report=json.loads((out/f'shard-{shard}.json').read_text())
2223
for suite in report['testResults']:
2324
seen.append(str(pathlib.Path(suite['name']).relative_to(root)))
2425
for k in counts:counts[k]+=report[{'passed':'numPassedTests','failed':'numFailedTests','pending':'numPendingTests'}[k]]
2526
assert len(seen)==len(set(seen)) and set(seen)==set(files),(len(seen),len(files),set(files)-set(seen))
26-
summary={'revision':expected,'counts':counts,'testFiles':len(files),'exactlyOnce':True,'finished':datetime.datetime.now(datetime.timezone.utc).isoformat()}
27+
summary={'revision':expected,'counts':counts,'testFiles':len(files),'exactlyOnce':True,'success':not failures and counts['failed']==0,'failedShards':failures,'finished':datetime.datetime.now(datetime.timezone.utc).isoformat()}
2728
(out/'summary.json').write_text(json.dumps(summary,indent=2)+'\n');print(json.dumps(summary),flush=True)
29+
30+
sys.exit(0 if summary['success'] else 1)

‎scripts/validation/release-native.cjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async function run(name, command, args, timeout = 360000, overrides = {}) {
3939
const built = await run('build', ...npmCommand(['run', 'build']));
4040
if (built && metadata.scope === 'repairs') {
4141
metadata.notRun = ['unchanged core/worker/lifecycle paths: reuse successful steps at 90516f8, run 35880834124'];
42-
await run('focused', process.execPath, ['node_modules/vitest/vitest.mjs', 'run', '__tests__/db-reopen-on-replace.test.ts', '__tests__/upgrade.test.ts', '__tests__/update-check.test.ts', '__tests__/cli-ui-command.test.ts', '--maxWorkers=1', '--minWorkers=1', '--reporter=default', '--reporter=json', `--outputFile.json=${path.join(out, 'focused.json')}`], 300000);
42+
await run('focused', process.execPath, ['node_modules/vitest/vitest.mjs', 'run', '__tests__/db-reopen-on-replace.test.ts', '__tests__/upgrade.test.ts', '__tests__/update-check.test.ts', '__tests__/git-index-currency.test.ts', '__tests__/cli-ui-command.test.ts', '--maxWorkers=1', '--minWorkers=1', '--reporter=default', '--reporter=json', `--outputFile.json=${path.join(out, 'focused.json')}`], 300000);
4343
await run('file-growth-race', process.execPath, ['scripts/validation/release-size-race.cjs','dist']);
4444
await run('installer-archives', process.execPath, ['scripts/validation/release-installers.cjs']);
4545
await run('security-negative', process.execPath, ['scripts/validation/release-security.cjs','.','dist']);

0 commit comments

Comments
 (0)