Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(train): refuse lossy UTF-8 conflict decoding [B3,R3,C7]
Corey Olsond519e5620ec8
diff --git a/src/train-mechanical-merge.js b/src/train-mechanical-merge.jsindex bbdb0653..e3299e3f 100644--- a/src/train-mechanical-merge.js+++ b/src/train-mechanical-merge.js@@ -100,9 +100,10 @@ export function resolveMechanicalMerge(root, files) {const modes = records.map(record => /^(100644|100755) [a-f0-9]+ [123]\t/u.exec(record)?.[1]);if (index.status !== 0 || records.length !== 3 || modes.some(mode => !mode || mode !== modes[0])) return null;const stages = [1, 2, 3].map(stage => spawnSync('git', ['--no-optional-locks', 'show', `:${stage}:${path}`],- { cwd: root, env: cleanGitEnvironment(), encoding: 'utf8' }));- if (stages.some(stage => stage.status !== 0)) return null;- const merged = mergeMechanicalSources(path, ...stages.map(stage => stage.stdout));+ { cwd: root, env: cleanGitEnvironment() }));+ if (stages.some(stage => stage.status !== 0 || !Buffer.isBuffer(stage.stdout)+ || !Buffer.from(stage.stdout.toString('utf8'), 'utf8').equals(stage.stdout))) return null;+ const merged = mergeMechanicalSources(path, ...stages.map(stage => stage.stdout.toString('utf8')));if (!merged) return null;resolutions.push({ path, ...merged });}diff --git a/test/train-mechanical-merge.test.js b/test/train-mechanical-merge.test.jsindex ebba3eca..0982260b 100644--- a/test/train-mechanical-merge.test.js+++ b/test/train-mechanical-merge.test.js@@ -18,7 +18,10 @@ import {} from 'node:test';import { createE2eHelpers } from './e2e-helpers.js';import { json } from './land-board-fixture.js';-import { mergeMechanicalSources } from '../src/train-mechanical-merge.js';+import {+ mergeMechanicalSources,+ resolveMechanicalMerge,+} from '../src/train-mechanical-merge.js';import {discoverFormats,formatTable,@@ -109,6 +112,30 @@ test('parallel train promotion retains its mechanical resolution receipt [B3,R3,assertAdditions(true);});+test('non-UTF8 bytes outside a registry stay untouched when resolution is refused [B3,R3,C7]', () => {+ const box = e2e.sandbox();+ const root = join(box.dir, 'raw-registry');+ mkdirSync(join(root, 'src'), { recursive: true });+ box.git(root, 'init', '-q', '-b', 'main');+ const source = text => Buffer.concat([Buffer.from([0xff]), Buffer.from('\n' + text)]);+ writeFileSync(join(root, FILE), source(BASE));+ box.git(root, 'add', '-A');+ box.git(root, 'commit', '-q', '-m', 'chore: preserve raw private registry');+ const base = box.git(root, 'rev-parse', 'HEAD');+ for (const name of ['alpha', 'beta']) {+ box.git(root, 'checkout', '-q', '--detach', base);+ writeFileSync(join(root, FILE), source(BASE.replace(' base:', ` ${name}: { item: true },\n base:`)));+ box.git(root, 'add', '-A');+ box.git(root, 'commit', '-q', '-m', `chore: add ${name} to raw private registry`);+ box.git(root, 'tag', name);+ }+ box.git(root, 'checkout', '-q', '--detach', 'alpha');+ assert.notEqual(box.tryGit(root, 'merge', '--no-edit', 'beta').status, 0);+ const before = readFileSync(join(root, FILE));+ assert.equal(resolveMechanicalMerge(root, [FILE]), null);+ assert.deepEqual(readFileSync(join(root, FILE)), before, 'refusal preserves every byte of the unmerged working file');+});+test('a registry edit remains a conflict and reopens instead of being unioned [B3,R3,C7]', () => {const box = project();const first = item(box, 1, BASE.replace('item: true', 'item: false'));