-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix(skills): jj-aware artifact guard and v2-named schema helpers (TML-3223) #30089
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
Open
tensordreams
wants to merge
6
commits into
main
Choose a base branch
from
tml-3223-skill-audit-scripts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+208
−30
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c1b386e
fix(skills): make the artifact guard jj-aware and name the schema hel…
tensordreams ed38d7d
fix(skills): reject symlinked escapes from the ignored wip/ tree (TML…
tensordreams 808a89d
fix(skills): resolve the jj workspace root via jj itself (TML-3223)
tensordreams 909ca1c
fix(skills): close symlink escapes in the wip/ artifact guard (TML-3223)
tensordreams 7552e14
test(skills): manage the guard test fixture with mkdtempDisposableSyn…
tensordreams 45627e1
refactor(skills): reuse isInside in ensureInsideRepo (TML-3223)
tensordreams 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
118 changes: 118 additions & 0 deletions
118
skills-contrib/review-fetch-phase/scripts/guard-review-artifacts-ignored.test.mjs
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,118 @@ | ||
| import { spawnSync } from 'node:child_process'; | ||
| import { mkdirSync, mkdtempDisposableSync, realpathSync, symlinkSync, writeFileSync } from 'node:fs'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { delimiter, dirname, join } from 'node:path'; | ||
| import { after, before, describe, it } from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| const guardPath = join(dirname(fileURLToPath(import.meta.url)), 'guard-review-artifacts-ignored.mjs'); | ||
|
|
||
| const FAKE_JJ_SCRIPT = `#!/bin/sh | ||
| case "$*" in | ||
| "workspace root --ignore-working-copy") ;; | ||
| *) echo "fake jj: unexpected args: $*" >&2; exit 2 ;; | ||
| esac | ||
| if [ -z "$FAKE_JJ_WORKSPACE_ROOT" ]; then | ||
| echo 'Error: There is no jj repo in "."' >&2 | ||
| exit 1 | ||
| fi | ||
| printf '%s\\n' "$FAKE_JJ_WORKSPACE_ROOT" | ||
| `; | ||
|
|
||
| let tempRoot; | ||
| let workspaceRoot; | ||
| let outsideRoot; | ||
| let fakeWorkspaceRoot; | ||
| let wipLinkWorkspaceRoot; | ||
| let fakeJjBinDir; | ||
|
|
||
| function runGuard(dir, { jjRoot = workspaceRoot, cwd = workspaceRoot } = {}) { | ||
| return spawnSync(process.execPath, [guardPath, '--dir', dir], { | ||
| cwd, | ||
| encoding: 'utf8', | ||
| env: { | ||
| ...process.env, | ||
| PATH: `${fakeJjBinDir}${delimiter}${process.env.PATH}`, | ||
| FAKE_JJ_WORKSPACE_ROOT: jjRoot ?? '', | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| describe('guard-review-artifacts-ignored in a jj workspace without git', () => { | ||
| before(() => { | ||
| tempRoot = mkdtempDisposableSync(join(tmpdir(), 'guard-review-')); | ||
| const base = realpathSync(tempRoot.path); | ||
| workspaceRoot = join(base, 'workspace'); | ||
| outsideRoot = join(base, 'outside'); | ||
| fakeWorkspaceRoot = join(base, 'fake-workspace'); | ||
| fakeJjBinDir = join(base, 'bin'); | ||
| wipLinkWorkspaceRoot = join(base, 'wip-link-workspace'); | ||
| mkdirSync(join(workspaceRoot, 'wip', 'reviews', 'x'), { recursive: true }); | ||
| mkdirSync(join(workspaceRoot, 'docs'), { recursive: true }); | ||
| mkdirSync(join(outsideRoot, 'reviews'), { recursive: true }); | ||
| mkdirSync(join(fakeWorkspaceRoot, '.jj'), { recursive: true }); | ||
| mkdirSync(join(fakeWorkspaceRoot, 'wip', 'reviews'), { recursive: true }); | ||
| mkdirSync(join(wipLinkWorkspaceRoot, 'docs', 'reviews'), { recursive: true }); | ||
| mkdirSync(fakeJjBinDir, { recursive: true }); | ||
| writeFileSync(join(fakeJjBinDir, 'jj'), FAKE_JJ_SCRIPT, { mode: 0o755 }); | ||
| symlinkSync(outsideRoot, join(workspaceRoot, 'wip', 'escape'), 'dir'); | ||
| symlinkSync(join(base, 'nonexistent'), join(workspaceRoot, 'wip', 'dangling'), 'dir'); | ||
| symlinkSync(join(wipLinkWorkspaceRoot, 'docs'), join(wipLinkWorkspaceRoot, 'wip'), 'dir'); | ||
| }); | ||
|
|
||
| after(() => { | ||
| tempRoot.remove(); | ||
| }); | ||
|
|
||
| it('accepts a directory under the ignored wip/ tree', () => { | ||
| const result = runGuard(join(workspaceRoot, 'wip', 'reviews', 'x')); | ||
| assert.equal(result.status, 0, result.stderr); | ||
| assert.match(result.stdout, /ok: review artifacts are under the ignored wip\/ tree/); | ||
| }); | ||
|
|
||
| it('rejects a directory outside the wip/ tree', () => { | ||
| const result = runGuard(join(workspaceRoot, 'docs')); | ||
| assert.equal(result.status, 1); | ||
| assert.match(result.stderr, /must live under the ignored wip\/ tree/); | ||
| }); | ||
|
|
||
| it('rejects a path that a symlink under wip/ points outside the workspace', () => { | ||
| const result = runGuard(join(workspaceRoot, 'wip', 'escape', 'reviews')); | ||
| assert.equal(result.status, 1); | ||
| assert.match(result.stderr, /outside/); | ||
| }); | ||
|
|
||
| it('rejects a path through a dangling symlink under wip/', () => { | ||
| const result = runGuard(join(workspaceRoot, 'wip', 'dangling', 'reviews')); | ||
| assert.equal(result.status, 1); | ||
| assert.match(result.stderr, /ENOENT/); | ||
| }); | ||
|
|
||
| it('rejects an artifact dir when wip itself is a symlink to a non-ignored directory', () => { | ||
| const result = runGuard(join(wipLinkWorkspaceRoot, 'wip', 'reviews'), { | ||
| jjRoot: wipLinkWorkspaceRoot, | ||
| cwd: wipLinkWorkspaceRoot, | ||
| }); | ||
| assert.equal(result.status, 1); | ||
| assert.match(result.stderr, /must live under the ignored wip\/ tree/); | ||
| }); | ||
|
|
||
| it('fails with ENOENT for a missing output path', () => { | ||
| const result = runGuard(join(workspaceRoot, 'wip', 'reviews', 'missing')); | ||
| assert.equal(result.status, 1); | ||
| assert.match(result.stderr, /ENOENT/); | ||
| }); | ||
|
|
||
| it('rejects a directory under another workspace marked only by a .jj directory', () => { | ||
| const result = runGuard(join(fakeWorkspaceRoot, 'wip', 'reviews')); | ||
| assert.equal(result.status, 1); | ||
| assert.match(result.stderr, /must stay inside the workspace/); | ||
| }); | ||
|
|
||
| it('fails when jj reports no workspace for the working directory', () => { | ||
| const result = runGuard(join(workspaceRoot, 'wip', 'reviews', 'x'), { jjRoot: null }); | ||
| assert.equal(result.status, 1); | ||
| assert.match(result.stderr, /not in a git repository or a jj workspace/); | ||
| }); | ||
| }); |
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
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.