-
Notifications
You must be signed in to change notification settings - Fork 0
feat(sdk): wire workspace:/tools.fs: scope-compiler into preflight (#308) #359
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
2 commits
Select commit
Hold shift + click to select a range
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
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,90 @@ | ||
| import { mkdtempSync, writeFileSync, rmSync } from 'node:fs'; | ||
| import { join } from 'node:path'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { preflight } from '../src/index.js'; | ||
| import type { PreflightResult, PreflightProbes, CliProbeResult } from '../src/preflight.js'; | ||
| import type { FlowSpec } from '../src/spec.js'; | ||
|
|
||
| const probes: PreflightProbes = { | ||
| cli: (): CliProbeResult => ({ exists: true, authenticated: true, modelAvailable: true }), | ||
| executor: () => true, | ||
| command: () => true, | ||
| helper: () => true, | ||
| }; | ||
|
|
||
| const baseFlow: FlowSpec = { | ||
| version: '0.1.0', | ||
| name: 'scope-test', | ||
| steps: [{ id: 'run', type: 'deterministic', command: 'true', maxIterations: 1 }], | ||
| }; | ||
|
|
||
| describe('preflight — path-scoped auth (#308)', () => { | ||
| it('accepts a grant the mount manifest can satisfy', () => { | ||
| const root = mkdtempSync(join(tmpdir(), 'scope-ok-')); | ||
| try { | ||
| writeFileSync(join(root, 'relayfile.mounts.json'), JSON.stringify({ | ||
| version: 1, mounts: { acme: [{ path: 'api', modes: ['readonly', 'readwrite'] }] }, | ||
| })); | ||
| const flow: FlowSpec = { ...baseFlow, workspace: 'acme/api: readonly' }; | ||
| const result = preflight(flow, { probes, projectSearchStart: root }) as PreflightResult; | ||
| expect(result.diagnostics.filter(d => d.severity === 'refusal')).toEqual([]); | ||
| expect(result.ok).toBe(true); | ||
| } finally { rmSync(root, { recursive: true, force: true }); } | ||
| }); | ||
|
|
||
| it('refuses a malformed grant with scope_syntax_invalid', () => { | ||
| const flow: FlowSpec = { ...baseFlow, workspace: 'not-a-grant' }; | ||
| const result = preflight(flow, { probes }) as PreflightResult; | ||
| const refusal = result.diagnostics.find(d => d.severity === 'refusal' && d.kind === 'scope_syntax_invalid'); | ||
| expect(refusal).toBeDefined(); | ||
| expect(result.ok).toBe(false); | ||
| }); | ||
|
|
||
| it('refuses an unknown mount with mount_unknown when a manifest is present', () => { | ||
| const root = mkdtempSync(join(tmpdir(), 'scope-unknown-')); | ||
| try { | ||
| writeFileSync(join(root, 'relayfile.mounts.json'), JSON.stringify({ | ||
| version: 1, mounts: { acme: [{ path: 'api', modes: ['readonly'] }] }, | ||
| })); | ||
| const flow: FlowSpec = { ...baseFlow, workspace: 'other/api: readonly' }; | ||
| const result = preflight(flow, { probes, projectSearchStart: root }) as PreflightResult; | ||
| const refusal = result.diagnostics.find(d => d.severity === 'refusal' && d.kind === 'mount_unknown'); | ||
| expect(refusal).toBeDefined(); | ||
| } finally { rmSync(root, { recursive: true, force: true }); } | ||
| }); | ||
|
|
||
| it('refuses an out-of-scope path or mode with scope_ungrantable', () => { | ||
| const root = mkdtempSync(join(tmpdir(), 'scope-ungrantable-')); | ||
| try { | ||
| writeFileSync(join(root, 'relayfile.mounts.json'), JSON.stringify({ | ||
| version: 1, mounts: { acme: [{ path: 'api', modes: ['readonly'] }] }, | ||
| })); | ||
| const flowPath: FlowSpec = { ...baseFlow, workspace: 'acme/other: readonly' }; | ||
| const pathResult = preflight(flowPath, { probes, projectSearchStart: root }) as PreflightResult; | ||
| expect(pathResult.diagnostics.find(d => d.severity === 'refusal' && d.kind === 'scope_ungrantable')).toBeDefined(); | ||
|
|
||
| const flowMode: FlowSpec = { ...baseFlow, workspace: 'acme/api: readwrite' }; | ||
| const modeResult = preflight(flowMode, { probes, projectSearchStart: root }) as PreflightResult; | ||
| expect(modeResult.diagnostics.find(d => d.severity === 'refusal' && d.kind === 'scope_ungrantable')).toBeDefined(); | ||
| } finally { rmSync(root, { recursive: true, force: true }); } | ||
| }); | ||
|
|
||
| it('honors tools.fs the same way as workspace', () => { | ||
| const root = mkdtempSync(join(tmpdir(), 'scope-toolsfs-')); | ||
| try { | ||
| writeFileSync(join(root, 'relayfile.mounts.json'), JSON.stringify({ | ||
| version: 1, mounts: { acme: [{ path: 'api', modes: ['readwrite'] }] }, | ||
| })); | ||
| const flow: FlowSpec = { ...baseFlow, tools: { fs: 'acme/api: readwrite' } }; | ||
| const result = preflight(flow, { probes, projectSearchStart: root }) as PreflightResult; | ||
| expect(result.diagnostics.filter(d => d.severity === 'refusal')).toEqual([]); | ||
| } finally { rmSync(root, { recursive: true, force: true }); } | ||
| }); | ||
|
|
||
| it('accepts absence of workspace and tools without probing anything', () => { | ||
| const result = preflight(baseFlow, { probes }) as PreflightResult; | ||
| expect(result.diagnostics.filter(d => d.severity === 'refusal')).toEqual([]); | ||
| expect(result.ok).toBe(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
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.
Manifest errors reported as unknown mounts
Medium Severity
scopeDiagnosticscatches everyreadMountRegistryfailure and replaces it with an empty registry, so corrupt JSON, an invalid manifest, or a permission error all surface asmount_unknown. The registry already throws a path-specific reason, but that message is discarded and the grant is described as missing from the manifest.Reviewed by Cursor Bugbot for commit 5c99a5c. Configure here.