Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/babysitter/artifacts/babysitter-fixer.flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ async function checkoutHead(c) {
const before = fingerprint();
rmSync(join(dir, ".git"), { recursive: true, force: true });
git("init", "-q");
git("config", "core.fileMode", "false");
git("fetch", "-q", "--no-tags", "--depth=50", c.origin ?? `https://github.com/${c.owner}/${c.repo}.git`, c.head);
git("reset", "-q", "--hard", c.head);
git("clean", "-q", reused && fingerprint() !== before ? "-fdx" : "-fd");
Expand Down Expand Up @@ -765,7 +766,7 @@ async function proposeChanges(c) {
const { copyFileSync, lstatSync, mkdtempSync, readdirSync, rmSync, utimesSync, writeFileSync } = await import("node:fs");
const { tmpdir } = await import("node:os");
const { resolve } = await import("node:path");
const environment = { ...process.env, GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: "/dev/null", GIT_CONFIG_COUNT: "2", GIT_CONFIG_KEY_0: "core.hooksPath", GIT_CONFIG_VALUE_0: "/dev/null", GIT_CONFIG_KEY_1: "core.quotePath", GIT_CONFIG_VALUE_1: "false" };
const environment = { ...process.env, GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: "/dev/null", GIT_CONFIG_COUNT: "3", GIT_CONFIG_KEY_0: "core.hooksPath", GIT_CONFIG_VALUE_0: "/dev/null", GIT_CONFIG_KEY_1: "core.quotePath", GIT_CONFIG_VALUE_1: "false", GIT_CONFIG_KEY_2: "core.fileMode", GIT_CONFIG_VALUE_2: "false" };
const checkoutGit = resolve(c.dir, ".git");
const scratch = mkdtempSync(`${tmpdir()}/babysitter-gitdir-`);
try {
Expand Down
4 changes: 2 additions & 2 deletions examples/babysitter/artifacts/babysitter-fixer.manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"schemaVersion": 1,
"artifact": "babysitter-fixer.flow.ts",
"bytes": 63346,
"sha256": "f107bcf907bb7f695fcdd2e21f23030a81a0ce5292dc0455374fddd5ac13f2cc",
"bytes": 63453,
"sha256": "fe9f2512421fdbeac327e360db078c2a33c2d3542590382807b75b65a666e4eb",
"policy": "../standalone-policy.json",
"policySha256": "e2fd08aaef4ea922146ad1330d7b7d7161f078f9c19e1499aa272636ae6e39a2",
"runtime": {
Expand Down
384 changes: 193 additions & 191 deletions examples/babysitter/evidence/p2-task-modes/02-all-babysitter-green.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
$ node examples/babysitter/build-standalone.mjs --check
Checked sha256:580bab1d31bfe05b2be4cbdfa74f8669efdb1067ba4a4bf126f871b432d7f834 (babysitter-standalone)
Checked sha256:f107bcf907bb7f695fcdd2e21f23030a81a0ce5292dc0455374fddd5ac13f2cc (babysitter-fixer)
Checked sha256:fe9f2512421fdbeac327e360db078c2a33c2d3542590382807b75b65a666e4eb (babysitter-fixer)
102 changes: 102 additions & 0 deletions examples/babysitter/evidence/p2-task-modes/09-filemode-mutation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Lost-executable-bit fix: mutation evidence. Produced from the repository root, at the commit that contains this file's script, by running verbatim:
# bash examples/babysitter/evidence/p2-task-modes/scripts/filemode-mutation.sh
# Each '+ ' line is the exact command run, printed shell-escaped (printf %q); everything else is its captured output, unedited.
# ---- output ----
+ sha256sum fix.ts
47b09cd11a13ccf9c88ddb3a52c6cab1c3452faf4173c23f410169a35adc7f3d fix.ts

### M1: the private git dir compares file modes (no core.fileMode=false)
+ python3 -c p=\'fix.ts\'\;s=open\(p\).read\(\)\;o=\"GIT_CONFIG_COUNT:\ \'3\'\,\ GIT_CONFIG_KEY_0:\ \'core.hooksPath\'\"\;assert\ o\ in\ s\;s=s.replace\(o\,\"GIT_CONFIG_COUNT:\ \'2\'\,\ GIT_CONFIG_KEY_0:\ \'core.hooksPath\'\"\,1\)\;open\(p\,\'w\'\).write\(s\)
+ git diff --stat -- fix.ts
examples/babysitter/fix.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
+ node --experimental-strip-types --test --test-name-pattern=dropped\ executable\ bits tests/task.test.ts
✖ a checkout whose filesystem dropped executable bits proposes only the real edits (187.191085ms)
ℹ tests 1
ℹ suites 0
ℹ pass 0
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 335.777005

✖ failing tests:

test at tests/task.test.ts:224:1
✖ a checkout whose filesystem dropped executable bits proposes only the real edits (187.191085ms)
AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
+ actual - expected

[
+ 'scripts/a.sh',
+ 'scripts/b.sh',
'src/retry.ts'
]

at TestContext.<anonymous> (file:///home/khaliqgant/Projects/AgentWorkforce/flows-worktrees/babysitter-filemode/examples/babysitter/tests/task.test.ts:232:10)
at async Test.run (node:internal/test_runner/test:1409:7)
at async startSubtestAfterBootstrap (node:internal/test_runner/harness:387:3) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: [ 'scripts/a.sh', 'scripts/b.sh', 'src/retry.ts' ],
expected: [ 'src/retry.ts' ],
operator: 'deepStrictEqual',
diff: 'simple'
}
+ git restore --source=HEAD -- fix.ts
+ sha256sum fix.ts
47b09cd11a13ccf9c88ddb3a52c6cab1c3452faf4173c23f410169a35adc7f3d fix.ts

### M2: the checkout's config compares file modes (no git config core.fileMode false)
+ python3 -c p=\'fix.ts\'\;s=open\(p\).read\(\)\;o=\"\ \ git\(\'config\'\,\ \'core.fileMode\'\,\ \'false\'\)\;\\n\"\;assert\ o\ in\ s\;open\(p\,\'w\'\).write\(s.replace\(o\,\'\'\,1\)\)
+ git diff --stat -- fix.ts
examples/babysitter/fix.ts | 1 -
1 file changed, 1 deletion(-)
+ node --experimental-strip-types --test --test-name-pattern=dropped\ executable\ bits tests/fixer.test.ts
✖ a checkout whose filesystem dropped executable bits reads as clean (122.230312ms)
ℹ tests 1
ℹ suites 0
ℹ pass 0
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 267.424655

✖ failing tests:

test at tests/fixer.test.ts:348:1
✖ a checkout whose filesystem dropped executable bits reads as clean (122.230312ms)
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
+ actual - expected

+ ' M bin/run.sh\n'
- ''

at TestContext.<anonymous> (file:///home/khaliqgant/Projects/AgentWorkforce/flows-worktrees/babysitter-filemode/examples/babysitter/tests/fixer.test.ts:358:10)
at async Test.run (node:internal/test_runner/test:1409:7)
at async startSubtestAfterBootstrap (node:internal/test_runner/harness:387:3) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: ' M bin/run.sh\n',
expected: '',
operator: 'strictEqual',
diff: 'simple'
}
+ git restore --source=HEAD -- fix.ts
+ sha256sum fix.ts
47b09cd11a13ccf9c88ddb3a52c6cab1c3452faf4173c23f410169a35adc7f3d fix.ts

### Restored: both tests
+ node --experimental-strip-types --test --test-name-pattern=dropped\ executable\ bits tests/fixer.test.ts tests/task.test.ts
✔ a checkout whose filesystem dropped executable bits reads as clean (121.761698ms)
✔ a checkout whose filesystem dropped executable bits proposes only the real edits (193.143973ms)
ℹ tests 2
ℹ suites 0
ℹ pass 2
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 344.756149
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Mutation evidence for the lost-executable-bit fix. Run from the repository root,
# at the commit that contains this script: bash examples/babysitter/evidence/p2-task-modes/scripts/filemode-mutation.sh
set -euo pipefail
export TMPDIR="$HOME/.agent-tmp"
cd "$(dirname "$0")/../../.."
git diff --quiet HEAD -- fix.ts || { echo "fix.ts differs from HEAD; commit it first" >&2; exit 1; }
trap 'git restore --source=HEAD -- fix.ts' EXIT
# Commands are printed shell-escaped (printf %q), so a printed line replays as run.
show() { printf '+'; printf ' %q' "$@"; printf '\n'; }
run() { show "$@"; "$@" 2>&1 || true; }
edit() { show "$@"; "$@"; }
run sha256sum fix.ts

echo; echo "### M1: the private git dir compares file modes (no core.fileMode=false)"
edit python3 -c "p='fix.ts';s=open(p).read();o=\"GIT_CONFIG_COUNT: '3', GIT_CONFIG_KEY_0: 'core.hooksPath'\";assert o in s;s=s.replace(o,\"GIT_CONFIG_COUNT: '2', GIT_CONFIG_KEY_0: 'core.hooksPath'\",1);open(p,'w').write(s)"
run git diff --stat -- fix.ts
run node --experimental-strip-types --test --test-name-pattern='dropped executable bits' tests/task.test.ts
run git restore --source=HEAD -- fix.ts
run sha256sum fix.ts

echo; echo "### M2: the checkout's config compares file modes (no git config core.fileMode false)"
edit python3 -c "p='fix.ts';s=open(p).read();o=\" git('config', 'core.fileMode', 'false');\n\";assert o in s;open(p,'w').write(s.replace(o,'',1))"
run git diff --stat -- fix.ts
run node --experimental-strip-types --test --test-name-pattern='dropped executable bits' tests/fixer.test.ts
run git restore --source=HEAD -- fix.ts
run sha256sum fix.ts

echo; echo "### Restored: both tests"
run node --experimental-strip-types --test --test-name-pattern='dropped executable bits' tests/fixer.test.ts tests/task.test.ts
5 changes: 4 additions & 1 deletion examples/babysitter/fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export async function checkoutHead(c: { owner: string; repo: string; head: strin
const before = fingerprint();
rmSync(join(dir, '.git'), { recursive: true, force: true });
git('init', '-q');
// The sandbox's filesystem may not keep executable bits: every executable
// would then read as changed, to the agent and in the proposal.
git('config', 'core.fileMode', 'false');
git('fetch', '-q', '--no-tags', '--depth=50', c.origin ?? `https://github.com/${c.owner}/${c.repo}.git`, c.head);
git('reset', '-q', '--hard', c.head);
git('clean', '-q', reused && fingerprint() !== before ? '-fdx' : '-fd');
Expand Down Expand Up @@ -171,7 +174,7 @@ export async function proposeChanges(c: ProposalInput): Promise<void> {
// git dir that only borrows the checkout's objects (read-only, via
// alternates) and a copy of its index (which keeps any unmerged stages,
// and the shared index files a split index points at).
const environment = { ...process.env, GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_COUNT: '2', GIT_CONFIG_KEY_0: 'core.hooksPath', GIT_CONFIG_VALUE_0: '/dev/null', GIT_CONFIG_KEY_1: 'core.quotePath', GIT_CONFIG_VALUE_1: 'false' };
const environment = { ...process.env, GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_COUNT: '3', GIT_CONFIG_KEY_0: 'core.hooksPath', GIT_CONFIG_VALUE_0: '/dev/null', GIT_CONFIG_KEY_1: 'core.quotePath', GIT_CONFIG_VALUE_1: 'false', GIT_CONFIG_KEY_2: 'core.fileMode', GIT_CONFIG_VALUE_2: 'false' };
const checkoutGit = resolve(c.dir, '.git');
const scratch = mkdtempSync(`${tmpdir()}/babysitter-gitdir-`);
try {
Expand Down
15 changes: 14 additions & 1 deletion examples/babysitter/tests/fixer.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import { mkdtempSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { chmodSync, mkdtempSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
Expand Down Expand Up @@ -345,6 +345,19 @@ function upstream(): { dir: string; commit: (files: Record<string, string>) => s
};
}

test('a checkout whose filesystem dropped executable bits reads as clean', async () => {
const up = upstream();
up.commit({ 'bin/run.sh': '#!/bin/sh\n' });
chmodSync(join(up.dir, 'bin/run.sh'), 0o755);
const head = up.commit({});
const runRoot = mkdtempSync(join(tmpdir(), 'babysitter-run-'));
await runCheckout(runRoot, up.dir, head);
const dir = join(runRoot, 'babysitter-checkout');
chmodSync(join(dir, 'bin/run.sh'), 0o644);
const status = execFileSync('git', ['-C', dir, 'status', '--porcelain'], { env: { ...process.env, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1' }, encoding: 'utf8' });
assert.equal(status, '');
});

test('a reused checkout keeps its dependencies but none of the agent\'s git state, and lands exactly on the head', async () => {
const up = upstream();
const first = up.commit({ '.gitignore': 'node_modules/\n', 'package.json': '{"name":"w"}\n', 'package-lock.json': '{"v":1}\n', 'src/a.ts': 'a\n' });
Expand Down
16 changes: 14 additions & 2 deletions examples/babysitter/tests/task.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import { mkdtempSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
import { chmodSync, mkdtempSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import test from 'node:test';
Expand Down Expand Up @@ -165,7 +165,7 @@ test('a merge too large to publish ends needs_human with an explanation instead

// Real repositories: a PR branch and a trunk that moved under it.
const gitEnv = { ...process.env, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1', GIT_AUTHOR_NAME: 't', GIT_AUTHOR_EMAIL: 't@t', GIT_COMMITTER_NAME: 't', GIT_COMMITTER_EMAIL: 't@t' };
function forked(): { up: string; head: string; trunk: string; checkout: string; git: (...a: string[]) => string } {
function forked(o: { executable?: string[] } = {}): { up: string; head: string; trunk: string; checkout: string; git: (...a: string[]) => string } {
const up = mkdtempSync(join(tmpdir(), 'babysitter-trunk-'));
const g = (dir: string) => (...a: string[]) => execFileSync('git', ['-C', dir, ...a], { env: gitEnv, encoding: 'utf8' }).trim();
const u = g(up);
Expand All @@ -175,6 +175,7 @@ function forked(): { up: string; head: string; trunk: string; checkout: string;
u('add', '-A'); u('commit', '-qm', 'base');
u('checkout', '-qb', 'pr');
write({ 'src/retry.ts': 'export const attempts = 3;\n', 'src/pr-only.ts': 'pr\n' });
for (const path of o.executable ?? []) { write({ [path]: '#!/bin/sh\n' }); chmodSync(join(up, path), 0o755); }
u('add', '-A'); u('commit', '-qm', 'pr');
const prHead = u('rev-parse', 'HEAD');
u('checkout', '-q', 'trunk');
Expand Down Expand Up @@ -220,6 +221,17 @@ const inOwnTmp = async <T>(run: () => Promise<T>): Promise<{ result: T; left: st
}
};

test('a checkout whose filesystem dropped executable bits proposes only the real edits', async () => {
// Live run #2 (Cloud run ba91b3b1): the sandbox checkout lost the mode of
// all 61 executables, and the proposal was refused for 63 changed files.
const r = forked({ executable: ['scripts/a.sh', 'scripts/b.sh'] });
for (const path of ['scripts/a.sh', 'scripts/b.sh']) chmodSync(join(r.checkout, path), 0o644);
writeFileSync(join(r.checkout, 'src/retry.ts'), 'export const attempts = 4;\n');
const p = await runPropose(r);
assert.equal(p.kind, 'babysitter-proposal');
assert.deepEqual(p.files, ['src/retry.ts']);
});

test('proposes from a checkout whose .git the sandbox left unwritable, touching nothing in it', async () => {
// Live run #1 (Cloud run c5c7bb01): after the agent step the checkout's
// .git was not writable, and rewriting .git/config failed with EACCES.
Expand Down
Loading