mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-20 07:04:17 +01:00
fix(windows): owned-read requires the read-only attribute on Windows; setup.ps1 passes arguments NUL-separated through a private file; Windows-only tests expect the owned-read approval
This commit is contained in:
1 parent
cb919cc770
commit
d2b601d9ae
5 files changed
+21
-9
No files matched your search
@@ -35,7 +35,7 @@ const artifactFiles = (phase: string) => ['methodology.md', 'methodology.json',
|
||||
'source-implementation.md', `${phase}-implementation.md`, 'close-packet.md'];
|
||||
|
||||
/** True only for this installation's autoplan/sections/*.md, or an immutable artifact in
|
||||
* <repo>/.gstack/tmp/autoplan/autoplan-<phase>-*\/ where <repo> is the session's project directory or contains it. */
|
||||
* <repo>/.gstack/tmp/autoplan/autoplan-<phase>-*\/ (read-only: mode 0444, or the read-only attribute on Windows) where <repo> is the session's project directory or contains it. */
|
||||
export function ownedAutoplanRead(file: unknown, cwd: string, root: string): boolean {
|
||||
if (typeof file !== 'string') return false;
|
||||
try {
|
||||
@@ -55,7 +55,7 @@ export function ownedAutoplanRead(file: unknown, cwd: string, root: string): boo
|
||||
const project = fs.realpathSync(nativePathSpelling(process.env.CLAUDE_PROJECT_DIR || cwd));
|
||||
return stat.isFile() && sameNativePath(store, path.join(owner, '.gstack', 'tmp', 'autoplan')) &&
|
||||
(sameNativePath(project, owner) || nativePathSpelling(project).startsWith(nativePathSpelling(owner) + path.sep)) &&
|
||||
(process.platform === 'win32' || (stat.mode & 0o777) === 0o444);
|
||||
(process.platform === 'win32' ? (stat.mode & 0o222) === 0 : (stat.mode & 0o777) === 0o444);
|
||||
} catch { return false; }
|
||||
}
|
||||
|
||||
|
||||
@@ -44,11 +44,22 @@ if (-not $bash -or -not (Test-Path -LiteralPath $bash -PathType Leaf)) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Arguments travel NUL-separated in a private file, never on the native command
|
||||
# line: PowerShell's native-argument quoting splits or merges arguments that
|
||||
# contain double quotes, so bash reads them back as an exact array instead.
|
||||
$argFile = [System.IO.Path]::GetTempFileName()
|
||||
$writer = New-Object System.IO.StreamWriter($argFile, $false, (New-Object System.Text.UTF8Encoding($false)))
|
||||
try {
|
||||
foreach ($arg in $args) { $writer.Write([string]$arg); $writer.Write([char]0) }
|
||||
} finally {
|
||||
$writer.Close()
|
||||
}
|
||||
Push-Location -LiteralPath $PSScriptRoot
|
||||
try {
|
||||
& $bash -c 'exec ./setup "$@"' setup @args
|
||||
& $bash -c 'mapfile -d "" -t argv < "$1"; rm -f "$1"; exec ./setup "${argv[@]}"' setup $argFile
|
||||
$code = $LASTEXITCODE
|
||||
} finally {
|
||||
Pop-Location
|
||||
Remove-Item -LiteralPath $argFile -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
exit $code
|
||||
@@ -124,7 +124,7 @@ describe('/autoplan owned reads after the skill turn', () => {
|
||||
const first = run(), second = run();
|
||||
expect(first.status).toBe(0); expect(second.status).toBe(0);
|
||||
const restore = /^RESTORE_PATH=(.+)$/m.exec(first.stdout)?.[1] ?? '';
|
||||
expect(path.dirname(restore)).toBe(path.join(repo, '.gstack', 'tmp', 'autoplan'));
|
||||
expect(path.resolve(path.dirname(restore))).toBe(path.join(repo, '.gstack', 'tmp', 'autoplan'));
|
||||
expect(path.basename(restore)).toMatch(/-autoplan-restore-\d{8}-\d{6}\.md$/);
|
||||
expect(fs.readFileSync(path.join(repo, '.git', 'info', 'exclude'), 'utf8').split('\n').filter(l => l === '/.gstack/tmp/')).toHaveLength(1);
|
||||
expect(spawnSync('git', ['status', '--porcelain', '--untracked-files=all'], { cwd: repo, encoding: 'utf8', timeout: 10_000 }).stdout).toBe('');
|
||||
|
||||
@@ -1274,8 +1274,8 @@ describe('Autoplan native journal roots and Windows spellings', () => {
|
||||
|
||||
test.if(windows)('CLAUDE_PROJECT_DIR spelled C:/ or c:\\ names the native journal cwd', async () => {
|
||||
const { f } = published();
|
||||
expect(await hook(f, f.cwd.replaceAll('\\', '/'))).toEqual({});
|
||||
expect(await hook(f, f.cwd[0]!.toLowerCase() + f.cwd.slice(1))).toEqual({});
|
||||
expect(await hook(f, f.cwd.replaceAll('\\', '/'))).toEqual(OWNED_READ_APPROVAL);
|
||||
expect(await hook(f, f.cwd[0]!.toLowerCase() + f.cwd.slice(1))).toEqual(OWNED_READ_APPROVAL);
|
||||
expect((await hook(f, f.cwd + '\\.') as any).hookSpecificOutput?.permissionDecision).toBe('deny');
|
||||
});
|
||||
|
||||
@@ -1465,7 +1465,7 @@ describe('Autoplan ownership in a linked git worktree session', () => {
|
||||
const entry = path.join(root, '.git', 'worktrees', 'session'); fs.mkdirSync(entry, { recursive: true });
|
||||
fs.writeFileSync(path.join(entry, 'gitdir'), lower(path.join(f.cwd, '.git')) + '\n');
|
||||
fs.writeFileSync(path.join(f.cwd, '.git'), `gitdir: ${lower(entry)}\n`);
|
||||
expect(await run(f, lower(root))).toEqual({});
|
||||
expect(await run(f, lower(root))).toEqual(OWNED_READ_APPROVAL);
|
||||
});
|
||||
|
||||
test('worktree.useRelativePaths links resolve against each file\'s own directory', async () => {
|
||||
|
||||
@@ -39,8 +39,9 @@ function runPs1(dir: string, args: string[], env: Record<string, string | undefi
|
||||
}
|
||||
|
||||
describe('setup.ps1', () => {
|
||||
test('passes arguments as an array to a constant bash script', () => {
|
||||
expect(SOURCE).toContain(`& $bash -c 'exec ./setup "$@"' setup @args`);
|
||||
test('passes arguments NUL-separated through a private file to a constant bash script', () => {
|
||||
expect(SOURCE).toContain(`& $bash -c 'mapfile -d "" -t argv < "$1"; rm -f "$1"; exec ./setup "\${argv[@]}"' setup $argFile`);
|
||||
expect(SOURCE).toContain('foreach ($arg in $args) { $writer.Write([string]$arg); $writer.Write([char]0) }');
|
||||
expect(SOURCE).not.toMatch(/-join|Invoke-Expression|\biex\b|git-bash\.exe/);
|
||||
expect([...SOURCE].every((c) => c.charCodeAt(0) < 128)).toBe(true);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user