-
Notifications
You must be signed in to change notification settings - Fork 253
feat(desktop): declare one thinking level across a relay's models at once #3448
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
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
159 changes: 159 additions & 0 deletions
159
apps/desktop/src/main/__tests__/relay-thinking-bulk.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,159 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { test } from 'node:test'; | ||
| import { | ||
| applyBulkThinkingLevel, | ||
| bulkThinkingLevelStates, | ||
| relayProfileWithThinkingLevels, | ||
| } from '../../renderer/settings/relay-thinking-bulk.js'; | ||
| import { DECLARABLE_RELAY_THINKING_LEVELS } from '@maka/core/model-thinking'; | ||
| import type { RelayModelProfile } from '@maka/core/model-thinking'; | ||
|
|
||
| const MODELS = ['alpha', 'beta', 'gamma']; | ||
|
|
||
| test('a level nobody declares reads as absent, and one everybody declares ticks the box', () => { | ||
| const draft: Record<string, RelayModelProfile> = { | ||
| alpha: { thinkingLevels: ['high'] }, | ||
| beta: { thinkingLevels: ['high'] }, | ||
| gamma: { thinkingLevels: ['high'] }, | ||
| }; | ||
| const states = bulkThinkingLevelStates(MODELS, draft, ['high', 'low']); | ||
| assert.deepEqual(states[0], { level: 'high', declaredCount: 3, total: 3, checked: true }); | ||
| assert.deepEqual(states[1], { level: 'low', declaredCount: 0, total: 3, checked: false }); | ||
| }); | ||
|
|
||
| test('partial coverage does not tick the box — only the count separates it from none', () => { | ||
| // The box is the affordance for "give this to everyone". Ticking at | ||
| // partial coverage would make the next click take the level AWAY from the | ||
| // rows that have it, which is the opposite of what the user just asked for. | ||
| const draft: Record<string, RelayModelProfile> = { | ||
| alpha: { thinkingLevels: ['high'] }, | ||
| beta: { thinkingLevels: ['high'] }, | ||
| }; | ||
| const [state] = bulkThinkingLevelStates(MODELS, draft, ['high']); | ||
| assert.equal(state?.checked, false); | ||
| assert.equal(state?.declaredCount, 2); | ||
| assert.equal(state?.total, 3); | ||
| }); | ||
|
|
||
| test('a repeated model id is one model, not two', () => { | ||
| const draft: Record<string, RelayModelProfile> = { alpha: { thinkingLevels: ['high'] } }; | ||
| const [state] = bulkThinkingLevelStates(['alpha', 'alpha'], draft, ['high']); | ||
| assert.deepEqual(state, { level: 'high', declaredCount: 1, total: 1, checked: true }); | ||
| }); | ||
|
|
||
| test('an empty selection ticks nothing rather than reading as fully covered', () => { | ||
| // 0 === 0 is the trap: `declaredCount === total` is true of an empty | ||
| // selection, which would present every level as declared everywhere. | ||
| for (const state of bulkThinkingLevelStates([], {}, DECLARABLE_RELAY_THINKING_LEVELS)) { | ||
| assert.equal(state.checked, false); | ||
| assert.equal(state.total, 0); | ||
| } | ||
| }); | ||
|
|
||
| test('ticking a level adds it to every model, including ones with no entry yet', () => { | ||
| const next = applyBulkThinkingLevel(MODELS, { alpha: { vision: true } }, 'high', true); | ||
| assert.deepEqual(next, { | ||
| alpha: { vision: true, thinkingLevels: ['high'] }, | ||
| beta: { thinkingLevels: ['high'] }, | ||
| gamma: { thinkingLevels: ['high'] }, | ||
| }); | ||
| }); | ||
|
|
||
| test('a bulk add leaves the levels a model already declared alone', () => { | ||
| const next = applyBulkThinkingLevel( | ||
| MODELS, | ||
| { alpha: { thinkingLevels: ['low', 'medium'] } }, | ||
| 'high', | ||
| true, | ||
| ); | ||
| assert.deepEqual(next.alpha?.thinkingLevels, ['low', 'medium', 'high']); | ||
| }); | ||
|
|
||
| test('ticking a level a model already has does not duplicate it', () => { | ||
| const next = applyBulkThinkingLevel( | ||
| ['alpha'], | ||
| { alpha: { thinkingLevels: ['high'] } }, | ||
| 'high', | ||
| true, | ||
| ); | ||
| assert.deepEqual(next.alpha?.thinkingLevels, ['high']); | ||
| }); | ||
|
|
||
| test('unticking removes only that level, and only from the selection', () => { | ||
| const next = applyBulkThinkingLevel( | ||
| ['alpha', 'beta'], | ||
| { | ||
| alpha: { thinkingLevels: ['low', 'high'] }, | ||
| beta: { thinkingLevels: ['high'] }, | ||
| gamma: { thinkingLevels: ['high'] }, | ||
| }, | ||
| 'high', | ||
| false, | ||
| ); | ||
| assert.deepEqual(next.alpha?.thinkingLevels, ['low']); | ||
| // beta held nothing but `high`: an entry with no keys left is not an | ||
| // entry, or the row keeps reading as declared and 保存 stays armed. | ||
| assert.equal('beta' in next, false); | ||
| // gamma is outside the selection — a bulk edit is scoped to the rows the | ||
| // control sits above. | ||
| assert.deepEqual(next.gamma?.thinkingLevels, ['high']); | ||
| }); | ||
|
|
||
| test('unticking keeps the other declarations on a model whose levels it empties', () => { | ||
| const next = applyBulkThinkingLevel( | ||
| ['alpha'], | ||
| { alpha: { thinkingLevels: ['high'], vision: true, contextWindow: 128_000 } }, | ||
| 'high', | ||
| false, | ||
| ); | ||
| assert.deepEqual(next.alpha, { vision: true, contextWindow: 128_000 }); | ||
| }); | ||
|
|
||
| test('a bulk edit does not reshuffle the draft under the rows being edited', () => { | ||
| const next = applyBulkThinkingLevel( | ||
| ['gamma', 'alpha'], | ||
| { alpha: { vision: true }, beta: { vision: false }, gamma: { vision: true } }, | ||
| 'high', | ||
| true, | ||
| ); | ||
| assert.deepEqual(Object.keys(next), ['alpha', 'beta', 'gamma']); | ||
| }); | ||
|
|
||
| test('a model id colliding with a prototype key stores an entry, not a prototype write', () => { | ||
| // Ids come off the relay's /models response. `draft['constructor']` on a | ||
| // plain object answers with Object's constructor rather than "absent", | ||
| // and assigning `__proto__` writes through the prototype. | ||
| const ids = ['__proto__', 'constructor', 'toString']; | ||
| const next = applyBulkThinkingLevel(ids, {}, 'high', true); | ||
| for (const id of ids) { | ||
| assert.deepEqual(Object.getOwnPropertyDescriptor(next, id)?.value, { | ||
| thinkingLevels: ['high'], | ||
| }); | ||
| } | ||
| assert.equal(({} as Record<string, unknown>).thinkingLevels, undefined); | ||
| // And the read side sees all three as declaring it, rather than answering | ||
| // "absent" for keys that resolve on Object.prototype. | ||
| const [state] = bulkThinkingLevelStates(ids, next, ['high']); | ||
| assert.deepEqual(state, { level: 'high', declaredCount: 3, total: 3, checked: true }); | ||
| }); | ||
|
|
||
| test('an emptied declaration collapses to undefined so the caller drops the key', () => { | ||
| assert.equal(relayProfileWithThinkingLevels({ thinkingLevels: ['high'] }, []), undefined); | ||
| assert.equal(relayProfileWithThinkingLevels({ thinkingLevels: ['high'] }, undefined), undefined); | ||
| assert.deepEqual(relayProfileWithThinkingLevels({ vision: true }, ['high']), { | ||
| vision: true, | ||
| thinkingLevels: ['high'], | ||
| }); | ||
| }); | ||
|
|
||
| test('clearing a level a model never declared leaves the draft untouched', () => { | ||
| const draft: Record<string, RelayModelProfile> = { alpha: { vision: true } }; | ||
| const next = applyBulkThinkingLevel(MODELS, draft, 'high', false); | ||
| assert.deepEqual(next, { alpha: { vision: true } }); | ||
| }); | ||
|
|
||
| test('the bulk edit does not mutate the draft it was handed', () => { | ||
| const draft: Record<string, RelayModelProfile> = { alpha: { thinkingLevels: ['low'] } }; | ||
| applyBulkThinkingLevel(MODELS, draft, 'high', true); | ||
| assert.deepEqual(draft, { alpha: { thinkingLevels: ['low'] } }); | ||
| }); |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Expose partial model coverage to assistive technology
Thanks for showing the partial
n/totalstate visually—it makes the batch behavior much easier to understand. Because this item also supplies anaria-label, however, the screen reader does not receive that visible description and cannot distinguish "none of the models declare this level" from "some models already declare it."Could we expose
thinkingBulkCoverage(...)througharia-descriptionor anaria-describedbyrelationship? A focused accessibility assertion for the partial state would be enough; the existing pure-function coverage does not need to be expanded further.