Repository navigation
fix(desktop): fold the usage fixture projection until no runs are pending #5889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
df99146
fix(desktop): fold the usage fixture projection until no runs are pen…
ggbdpq 2aff086
test(desktop): seed past the projection limit so the fold loop is act…
ggbdpq b65ce4e
Merge remote-tracking branch 'upstream/main' into fix/usage-fixture-f…
ggbdpq 78e4b0e
Merge remote-tracking branch 'upstream/main' into fix/usage-fixture-f…
ggbdpq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
apps/desktop/src/main/__tests__/e2e-fixture-usage-fold.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import { mkdtemp, rm } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { strict as assert } from 'node:assert'; | ||
| import { test } from 'node:test'; | ||
| import { resolveStorageRoot, tryAcquireInteractiveRootOwner } from '@maka/storage/root-authority'; | ||
| import { openInteractiveUsageStoresForWrite } from '@maka/storage/usage-stores'; | ||
| import { seedE2eFixture } from '../e2e-fixture.js'; | ||
| import { usageStatsRecords } from '../e2e-fixture/scenarios-usage.js'; | ||
| import { E2E_FIXTURE_NOW } from '../e2e-fixture/seed-helpers.js'; | ||
|
|
||
| test('settings-usage fixture folds the canonical usage projection until no run is pending', async () => { | ||
| const workspaceRoot = await mkdtemp(join(tmpdir(), 'e2e-usage-fold-')); | ||
| try { | ||
| await seedE2eFixture({ | ||
| workspaceRoot, | ||
| fixture: { | ||
| scenario: 'settings-usage', | ||
| workspaceName: 'e2e-fixture-settings-usage', | ||
| reducedMotion: false, | ||
| theme: null, | ||
| locale: null, | ||
| timezone: null, | ||
| platform: null, | ||
| }, | ||
| now: E2E_FIXTURE_NOW, | ||
| // The scenario seeds five model-call runs, under the ledger's default | ||
| // 16-run pass bound, so a single-pass seed would satisfy the assertions | ||
| // below. Capping each pass at 2 forces the fold to loop (2 + 2 + 1), which | ||
| // makes a reverted single-pass seed fail the first-read assertion. | ||
| projectionCatchUpLimit: 2, | ||
| }); | ||
|
|
||
| const storageRoot = await resolveStorageRoot({ path: workspaceRoot, kind: 'interactive' }); | ||
| const owner = await tryAcquireInteractiveRootOwner(storageRoot); | ||
| assert.ok(owner, 'the fixture must release the storage root so readers can acquire it'); | ||
| const usage = await openInteractiveUsageStoresForWrite(owner.lease); | ||
| try { | ||
| // The page's first read must already see every seeded model call; the | ||
| // fixture folds the appended attempts into the read model before closing. | ||
| const expectedRequests = usageStatsRecords(E2E_FIXTURE_NOW).modelCalls.length; | ||
| const summary = await usage.modelCalls.modelCallSummary({ range: 'all' }, E2E_FIXTURE_NOW); | ||
| assert.equal( | ||
| summary.projection.totalRequests, | ||
| expectedRequests, | ||
| 'the first read must see every seeded model call', | ||
| ); | ||
| // One catch-up pass bounds how many lagging runs it folds, so a complete | ||
| // fold leaves nothing pending for later reads to repair. | ||
| const projection = await usage.modelCalls.catchUpModelCallProjection(); | ||
| assert.equal(projection.pendingRuns, 0, 'no lagging run may outlive the fixture seed'); | ||
| } finally { | ||
| await usage.close(); | ||
| await owner.close(); | ||
| } | ||
| } finally { | ||
| await rm(workspaceRoot, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.