fix(web): await replacement refresh coverage

This commit is contained in:
2026-07-22 14:21:33 +08:00
parent 51c6fea343
commit 19f9e163e2
6 changed files with 186 additions and 26 deletions

View File

@@ -55,3 +55,35 @@ test('full and targeted refreshes supersede only when their coverage overlaps gl
assert.equal(full.signal.aborted, true)
assert.equal(newerProjectA.isCurrent(), true)
})
test('project A superseded by a failing full refresh is not considered covered', async () => {
const coordinator = createProjectRefreshCoordinator()
const projectA = coordinator.beginProject('project-a')
const full = coordinator.beginFull()
full.finish(false)
assert.equal(await projectA.waitForCoverage(), false)
})
test('only a successful replacement confirms coverage of a superseded project', async () => {
const coordinator = createProjectRefreshCoordinator()
const firstProjectA = coordinator.beginProject('project-a')
const newerProjectA = coordinator.beginProject('project-a')
newerProjectA.finish(true)
assert.equal(await firstProjectA.waitForCoverage(), true)
})
test('a successful full refresh covers every targeted request it superseded', async () => {
const coordinator = createProjectRefreshCoordinator()
const projectA = coordinator.beginProject('project-a')
const projectB = coordinator.beginProject('project-b')
const full = coordinator.beginFull()
full.finish(true)
assert.equal(await projectA.waitForCoverage(), true)
assert.equal(await projectB.waitForCoverage(), true)
})

View File

@@ -0,0 +1,29 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { runRecoveryRefresh } from '../src/app/recovery-refresh.ts'
test('a failed recovery never announces refreshed success', async () => {
const events = []
await assert.rejects(() => runRecoveryRefresh(
async () => {
events.push('refresh')
throw new Error('still stale')
},
() => events.push('success'),
), /still stale/)
assert.deepEqual(events, ['refresh'])
})
test('recovery announces success only after every requested refresh resolves', async () => {
const events = []
await runRecoveryRefresh(
async () => events.push('refresh'),
() => events.push('success'),
)
assert.deepEqual(events, ['refresh', 'success'])
})

View File

@@ -4,6 +4,7 @@ const requiredFiles = [
'src/app/App.tsx',
'src/app/mutation-refresh.ts',
'src/app/project-refresh-coordinator.ts',
'src/app/recovery-refresh.ts',
'src/pages/login.tsx',
'src/pages/workspace-body.tsx',
'src/pages/workspace-home.tsx',
@@ -33,6 +34,7 @@ const requiredFiles = [
'scripts/mutation-refresh.test.mjs',
'scripts/mutation-wiring.test.mjs',
'scripts/project-refresh-coordinator.test.mjs',
'scripts/recovery-refresh.test.mjs',
]
const failures = requiredFiles.filter((file) => !existsSync(file)).map((file) => `missing ${file}`)