People's changes now reach the target branch the same way the agent's do. The IDE credential carries a ref prefix and the Git service runs a pre-receive hook on every push that refuses updates outside it, so the IDE can push only `ide/` branches; the platform's own integration is unaffected. - A wish may name a source branch. The run starts from that branch's head, the agent builds on it, and verification, repair rounds, merging onto a moved target and conflict repair work as before. A missing branch makes the run wait (git_storage) until it is pushed. - Release risk is now computed from the target branch before integration, not from where the run started: a migration committed on the source branch would otherwise have been missed and could have skipped approval. - Clones work on `ide/work`; a plain `git push` publishes it. - The console lists a project's IDE branches with a button to submit a wish that merges one, and the new-wish form has a starting-point field; MCP `submit_wish` accepts `sourceBranch`. The Git service lists branches under a prefix for this (`POST /refs`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
3.3 KiB
TypeScript
62 lines
3.3 KiB
TypeScript
import { it, expect } from 'vitest';
|
|
import { execFile } from 'node:child_process';
|
|
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { promisify } from 'node:util';
|
|
import { branchesIn, installHooks, issueGitToken, verifyGitToken } from '../src/service.js';
|
|
|
|
// Runs without opening a port: the push goes over Git's local transport, which runs the same hook.
|
|
const run = promisify(execFile);
|
|
const git = (cwd: string, args: string[], env: Record<string, string> = {}) =>
|
|
run('git', ['-c', 'user.name=Fixture', '-c', 'user.email=fixture@example.invalid', ...args], {
|
|
cwd,
|
|
env: { ...process.env, ...env },
|
|
}).then(result => result.stdout.trim());
|
|
|
|
it('lets a credential scoped to ide/ push only ide/ branches, and lists them', async () => {
|
|
const root = await mkdtemp(path.join(os.tmpdir(), 'wishforge-git-hooks-'));
|
|
try {
|
|
const hooks = await installHooks(root);
|
|
const repository = path.join(root, 'project.git');
|
|
await git(root, ['init', '--quiet', '--bare', '--initial-branch=main', repository]);
|
|
// Over HTTP the service sets core.hooksPath for each request; a local push reads it from the repository.
|
|
await git(repository, ['config', 'core.hooksPath', hooks]);
|
|
const clone = path.join(root, 'clone');
|
|
await git(root, ['clone', '--quiet', repository, clone]);
|
|
await writeFile(path.join(clone, 'a.txt'), 'a\n');
|
|
await git(clone, ['add', 'a.txt']);
|
|
await git(clone, ['commit', '--quiet', '-m', 'A']);
|
|
// Without a scope (the platform's own integration pushes) any branch may be updated.
|
|
await git(clone, ['push', '--quiet', 'origin', 'HEAD:refs/heads/main']);
|
|
const integrated = await git(repository, ['rev-parse', 'main']);
|
|
|
|
await writeFile(path.join(clone, 'b.txt'), 'b\n');
|
|
await git(clone, ['add', 'b.txt']);
|
|
await git(clone, ['commit', '--quiet', '-m', 'B']);
|
|
const ide = { WISHFORGE_REF_PREFIX: 'refs/heads/ide/' };
|
|
await expect(git(clone, ['push', 'origin', 'HEAD:refs/heads/main'], ide)).rejects.toThrow(
|
|
/只能推送 ide\/ 开头的分支/,
|
|
);
|
|
expect(await git(repository, ['rev-parse', 'main'])).toBe(integrated);
|
|
await git(clone, ['push', '--quiet', 'origin', 'HEAD:refs/heads/ide/work'], ide);
|
|
expect(await branchesIn(repository, 'refs/heads/ide/')).toEqual([
|
|
{ name: 'ide/work', commit: await git(clone, ['rev-parse', 'HEAD']), updatedAt: expect.any(String) },
|
|
]);
|
|
await expect(branchesIn(repository, 'refs/heads/')).rejects.toMatchObject({ code: 'INVALID_REF' });
|
|
} finally {
|
|
await rm(root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
it('carries the push scope in the signed token and refuses a malformed one', () => {
|
|
const secret = 's'.repeat(32);
|
|
const claims = { aud: 'wishforge-git' as const, tenantId: 't', projectId: 'p', permission: 'write' as const };
|
|
const scoped = issueGitToken({ ...claims, iat: 100, exp: 400, refPrefix: 'refs/heads/ide/' }, secret);
|
|
expect(verifyGitToken(scoped, secret, { tenantId: 't', projectId: 'p', write: true }, 200).refPrefix).toBe(
|
|
'refs/heads/ide/',
|
|
);
|
|
const broad = issueGitToken({ ...claims, iat: 100, exp: 400, refPrefix: 'refs/heads/' }, secret);
|
|
expect(() => verifyGitToken(broad, secret, { tenantId: 't', projectId: 'p', write: true }, 200)).toThrow();
|
|
});
|