Repository navigation
Hooks: whole-space baseline at prompt submit, compared at Stop (#124, #127) #126
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
9 commits
Select commit
Hold shift + click to select a range
9fbc647
Hooks: compare against each file's first baseline in a session
mindsocket 45380d1
Hooks: whole-space baseline at prompt submit, compared at Stop (#127)
mindsocket e7b7ba8
Hook e2e harness: load no user settings or CLAUDE.md
mindsocket c24c291
Use cases: keep validate-file command and API usage for single-file v…
mindsocket cc03ef3
Fix on-prompt test using tmpdir() as unrelated cwd
mindsocket 6ecfeb8
Merge branch 'main' into fix/124-hook-tests
mindsocket e6f5d44
Merge branch 'main' into fix/124-hook-tests
mindsocket af6afef
Update docs/use-cases.md wording for plugin hook redesign
mindsocket e8aa55d
Merge remote-tracking branch 'origin/main' into fix/124-hook-tests
mindsocket 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /** | ||
| * Unit tests for plugin/scripts/on-prompt.ts | ||
| * | ||
| * Tests call runOnPrompt() directly — no Claude process involved. | ||
| */ | ||
|
|
||
| import { afterEach, beforeEach, describe, expect, it } from 'bun:test'; | ||
| import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { runOnPrompt } from '../../plugin/scripts/on-prompt'; | ||
| import { loadState, saveState, stateFilePath } from '../../plugin/scripts/state'; | ||
| import { type IsolatedFixtures, isolateFixtures } from '../fixture-utils'; | ||
|
|
||
| const SCTX_BIN = join(import.meta.dir, '../../src/index.ts'); | ||
|
|
||
| let fixtures: IsolatedFixtures; | ||
| let stateDir: string; | ||
| let sessionId: string; | ||
|
|
||
| beforeEach(() => { | ||
| fixtures = isolateFixtures(); | ||
| stateDir = join(tmpdir(), `ost-on-prompt-state-${crypto.randomUUID()}`); | ||
| sessionId = crypto.randomUUID(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| fixtures.cleanup(); | ||
| rmSync(stateDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| const opts = () => ({ stateDir, sctxBin: SCTX_BIN, configPath: fixtures.configPath }); | ||
| const stateFile = () => stateFilePath(sessionId, opts()); | ||
|
|
||
| describe('Baselines', () => { | ||
| it('baselines a space inside the session directory', async () => { | ||
| await runOnPrompt({ session_id: sessionId, cwd: fixtures.fixtureDir }, opts()); | ||
|
|
||
| const { baseline, latest } = loadState(stateFile()); | ||
| expect(Object.keys(baseline)).toEqual(['test-space']); | ||
| expect(baseline['test-space']!.path).toBe(fixtures.vaultDir); | ||
| expect(Object.keys(baseline['test-space']!.issues)).toEqual(['broken.md']); | ||
| expect(baseline['test-space']!.issues['broken.md']).toContain('broken-link:[[Nonexistent Node]]'); | ||
| expect(latest).toEqual(baseline); | ||
| }); | ||
|
|
||
| it('baselines a space that contains the session directory', async () => { | ||
| const subdir = join(fixtures.vaultDir, 'sub'); | ||
| mkdirSync(subdir); | ||
|
|
||
| await runOnPrompt({ session_id: sessionId, cwd: subdir }, opts()); | ||
|
|
||
| expect(Object.keys(loadState(stateFile()).baseline)).toEqual(['test-space']); | ||
| }); | ||
|
|
||
| it('writes no state when no space is related to the session directory', async () => { | ||
| // A sibling of the fixture dir, not tmpdir() itself: on Linux the fixture lives under tmpdir() | ||
| const unrelated = join(tmpdir(), `ost-on-prompt-unrelated-${crypto.randomUUID()}`); | ||
|
|
||
| await runOnPrompt({ session_id: sessionId, cwd: unrelated }, opts()); | ||
|
|
||
| expect(existsSync(stateFile())).toBe(false); | ||
| }); | ||
|
|
||
| it('does nothing without a cwd', async () => { | ||
| await runOnPrompt({ session_id: sessionId }, opts()); | ||
|
|
||
| expect(existsSync(stateFile())).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Existing state', () => { | ||
| it('keeps an existing baseline when the previous Stop never ran', async () => { | ||
| await runOnPrompt({ session_id: sessionId, cwd: fixtures.fixtureDir }, opts()); | ||
| writeFileSync( | ||
| join(fixtures.vaultDir, 'valid.md'), | ||
| '---\ntype: mission\nparent: "[[Ghost Node]]"\nstatus: identified\n---\n\n# Test Title\n', | ||
| ); | ||
|
|
||
| await runOnPrompt({ session_id: sessionId, cwd: fixtures.fixtureDir }, opts()); | ||
|
|
||
| expect(loadState(stateFile()).baseline['test-space']!.issues['valid.md']).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('reuses the latest results without validating when the space is unchanged', async () => { | ||
| await runOnPrompt({ session_id: sessionId, cwd: fixtures.fixtureDir }, opts()); | ||
| // Simulate a completed turn, and mark the latest results so reuse is observable | ||
| const state = loadState(stateFile()); | ||
| const latest = state.latest['test-space']!; | ||
| latest.issues = { 'marker.md': [] }; | ||
| saveState(stateFile(), { baseline: {}, latest: { 'test-space': latest } }); | ||
|
|
||
| await runOnPrompt({ session_id: sessionId, cwd: fixtures.fixtureDir }, opts()); | ||
|
|
||
| expect(Object.keys(loadState(stateFile()).baseline['test-space']!.issues)).toEqual(['marker.md']); | ||
| }); | ||
|
|
||
| it('validates again when the space has changed since the latest results', async () => { | ||
| await runOnPrompt({ session_id: sessionId, cwd: fixtures.fixtureDir }, opts()); | ||
| const state = loadState(stateFile()); | ||
| saveState(stateFile(), { baseline: {}, latest: state.latest }); | ||
| writeFileSync( | ||
| join(fixtures.vaultDir, 'broken.md'), | ||
| '---\ntype: mission\nparent: "[[Root]]"\nstatus: identified\n---\n\n# Broken Note\n', | ||
| ); | ||
|
|
||
| await runOnPrompt({ session_id: sessionId, cwd: fixtures.fixtureDir }, opts()); | ||
|
|
||
| expect(loadState(stateFile()).baseline['test-space']!.issues).toEqual({}); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.