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
7 changes: 5 additions & 2 deletions AUTOMATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,11 @@ Discussion builds and inline notes remain unsupported; #502 is still deferred.
### Frozen authorization and bounded spending

Preflight verifies owner identity, default-branch workflow code, the current
scope policy and its ancestry, acceptance, and existing contributions. Open
linked or possibly competing PRs stop the run, including ambiguous references.
scope policy and its ancestry, acceptance, and existing contributions. Open PRs
linked to the target Issue or naming it in their title/body stop the run for
owner review. Citing an open PR as related work does not by itself reserve the
Issue or block an independently accepted task. References and contributor credit
remain in the agreement, and their approved revisions are still checked.
The agreement, discussion, exact source revision, control fingerprints, and
short-lived App-access proof are frozen. An immutable spending reservation
precedes inference. The model-start guard repeats authorization and rejects App
Expand Down
9 changes: 4 additions & 5 deletions tools/issue-implementation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ async function existingBuild(github, target, acceptance) {
throw new Error("An implementation branch exists without a confirmed PR; inspect the earlier write before recovery.");
}

async function competingContributions(github, target, acceptance) {
const associated = new Set(acceptance.references.map(reference => reference.number));
async function competingContributions(github, target) {
const query = `query ImplementationContributions($owner:String!,$repo:String!,$number:Int!,$after:String) {
repository(owner:$owner,name:$repo) { issue(number:$number) {
timelineItems(first:100,after:$after,itemTypes:[CROSS_REFERENCED_EVENT,CONNECTED_EVENT]) {
Expand Down Expand Up @@ -309,7 +308,7 @@ async function competingContributions(github, target, acceptance) {
for (const pr of prs) {
requireValue(typeof pr.title === "string" && (pr.body === null || typeof pr.body === "string"),
"Open-contribution metadata is incomplete.");
requireValue(!associated.has(pr.number) && !mention.test(`${pr.title}\n${pr.body ?? ""}`),
requireValue(!mention.test(`${pr.title}\n${pr.body ?? ""}`),
`Open PR #${pr.number} may already implement this Issue; obtain owner guidance instead of a competing patch.`);
}
if (prs.length < 100) return;
Expand Down Expand Up @@ -338,7 +337,7 @@ export async function prepareBuild(github, context, env, clock = () => new Date(
request.mode === "command" ? request.acceptanceId : request.command.acceptanceId, request.command?.bodyHash, current);
const existing = await existingBuild(github, target, acceptance);
if (existing) return existing;
await competingContributions(github, target, acceptance);
await competingContributions(github, target);
requireValue(!await priorIntent(github, `${BUILD_WRITE_PREFIX}${scopeKey(target, acceptance)}`),
"An earlier publication is unresolved; inspect it before requesting more work.");
if (request.mode === "command") {
Expand Down Expand Up @@ -395,7 +394,7 @@ export async function verifyBuildAuthorization(github, context, env, prepared, c
const acceptance = await acceptanceRecord(github, thread, request.command.acceptanceId, request.command.bodyHash, current);
requireValue(same(acceptance, prepared.acceptance) && snapshotHash(thread) === prepared.snapshotHash,
"The acceptance or discussion changed after authorization; obtain a new owner decision.");
await competingContributions(github, request.target, acceptance);
await competingContributions(github, request.target);
return request;
}

Expand Down
70 changes: 64 additions & 6 deletions tools/tests/issue-implementation.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ const repo = { id: REPOSITORY.id, full_name: "microsoft/TypeChat", private: fals
const target = { kind: "issue", number: 75, id: "I_75", url: "https://github.com/microsoft/TypeChat/issues/75" };
const original = "export const value = 1;\n";

function fixture() {
function fixture(references = []) {
const policyText = "The project direction owner is **@robgruen**.\nPreserve schema accuracy.\n";
const fingerprints = Object.fromEntries(BUILD_CONTROL_PATHS.map(file => [file, blobHash(file)]));
fingerprints["GOALS.md"] = blobHash(policyText);
const body = renderAcceptance({
target, producer: { runId: 50, attempt: 1, commit: POLICY }, marker: "e".repeat(64),
draft: { proposal: { goal: "Preserve correct values.", scope: ["Fix the agreed value."], nonGoals: ["No other behavior changes."] },
suggestedCriteria: ["A deterministic test verifies the value."], pullRequests: [] },
suggestedCriteria: ["A deterministic test verifies the value."], pullRequests: references },
});
const owner = { __typename: "User", login: OWNER.login, id: "OWNER" };
const bot = { __typename: "Bot", login: "github-actions", id: ACTIONS_BOT_ID };
Expand All @@ -53,7 +53,13 @@ function fixture() {
lastEditedAt: null, author: owner, repository: { nameWithOwner: "microsoft/TypeChat", isPrivate: false } },
baseline: [...Object.entries(fingerprints).map(([file, sha]) => ({ path: file, type: "blob", mode: "100644", sha })),
{ path: "typescript/src/value.ts", type: "blob", mode: "100644", sha: blobHash(original) }],
ref: null, pr: null, competitors: [], linked: [], writes: [], createdEntries: [], persistPrError: false, prError: null,
ref: null, pr: null, competitors: references.map(reference => ({
number: reference.number, title: "Related work on another Issue", body: "Fixes #454",
})),
referenceData: new Map(references.map(reference => [reference.number, {
number: reference.number, state: "open", head: { sha: reference.headSha }, base: { repo: { id: REPOSITORY.id } },
}])),
linked: [], writes: [], createdEntries: [], persistPrError: false, prError: null,
};
const context = {
eventName: "issue_comment", actor: OWNER.login, sha: SHA, runId: 100,
Expand Down Expand Up @@ -100,7 +106,10 @@ function fixture() {
},
pulls: {
list: async input => ({ data: structuredClone(input.state === "all" ? state.pr ? [state.pr] : [] : state.competitors) }),
get: async () => { throw new Error("No contribution fetch expected."); },
get: async ({ pull_number }) => {
assert.ok(state.referenceData.has(pull_number), "No unexpected contribution fetch.");
return { data: structuredClone(state.referenceData.get(pull_number)) };
},
},
git: {
getTree: async ({ tree_sha }) => ({ data: { truncated: false, tree: structuredClone(tree_sha === TREE ? state.createdEntries :
Expand Down Expand Up @@ -172,8 +181,8 @@ function fixture() {
return { state, context, env, github, writer, proof, artifact };
}

async function preparedFixture() {
const f = fixture();
async function preparedFixture(references = []) {
const f = fixture(references);
const plan = await prepareBuild(f.github, f.context, f.env, clock);
f.prepared = freezeBuild(plan, f.proof, clock);
f.candidate = { version: 1, contextHash: digest(f.prepared), baseSha: SHA, summary: "Correct the agreed value.", limitations: [],
Expand Down Expand Up @@ -205,6 +214,55 @@ test("the public durable acceptance generates an exact, copyable Issue command",
assert.equal(parseAcceptedWork(f.state.comments[1].body, target).terms.goal, "Preserve correct values.");
});

test("a cited open PR for different work does not block command preparation", async () => {
const f = fixture([{ number: 466, headSha: "f".repeat(40) }]);
f.context.eventName = "workflow_dispatch";
f.context.payload.inputs = { issue: "75", acceptance: "41" };
delete f.env.TYPECHAT_IMPLEMENTATION_ENABLED;
const result = await prepareBuild(f.github, f.context, f.env, clock);
assert.equal(result.mode, "command");
assert.equal(result.command, buildCommand(41, digest(f.state.comments[1].body)));
assert.equal(result.enabled, false);
assert.equal(f.state.artifacts.size, 0);
assert.equal(f.state.writes.length, 0);
});

test("a related citation is preserved through preflight and verified publication", async () => {
const references = [{ number: 466, headSha: "f".repeat(40) }];
const f = await preparedFixture(references);
assert.deepEqual(f.prepared.acceptance.references, references);
const result = await f.publish();
assert.equal(result.mode, "published");
assert.ok(f.state.pr.body.includes(f.prepared.acceptance.body));
assert.equal(f.state.writes.filter(operation => operation === "branch").length, 1);
assert.equal(f.state.writes.filter(operation => operation === "pr").length, 1);
});

test("a cited PR still blocks when it is linked to or names the target Issue", async () => {
for (const linked of [true, false]) {
const f = fixture([{ number: 466, headSha: "f".repeat(40) }]);
if (linked) f.state.linked.push({ source: { number: 466, state: "OPEN" } });
else f.state.competitors[0].body = "Fixes #75";
await assert.rejects(() => prepareBuild(f.github, f.context, f.env, clock), /linked to this Issue|may already implement/);
assert.equal(f.state.writes.length, 0);
}
});

test("a related reference becoming competing work blocks publication", async () => {
const f = await preparedFixture([{ number: 466, headSha: "f".repeat(40) }]);
f.state.competitors[0].body = "Implements #75";
await assert.rejects(() => checkBuildPublication(f.github, f.context, f.env,
f.prepared, f.candidate, f.scan, f.checks, f.evidence, clock), /may already implement/);
assert.equal(f.state.writes.length, 0);
});

test("a related reference still requires its approved revision to remain current", async () => {
const f = await preparedFixture([{ number: 466, headSha: "f".repeat(40) }]);
f.state.referenceData.get(466).head.sha = "0".repeat(40);
await assert.rejects(() => verifyBuildAuthorization(f.github, f.context, f.env, f.prepared, clock), /Accepted contribution #466 changed/);
assert.equal(f.state.writes.length, 0);
});

for (const body of ["/typechat build 1:abc", `/typechat build 1:${"f".repeat(64)}\nAdd another feature`,
`/typechat accept 1:${"f".repeat(64)}`, `/typechat build 9007199254740993:${"f".repeat(64)}`]) {
test(`reject unsupported build syntax: ${body.slice(0, 40)}`, () => assert.throws(() => parseBuildCommand(body)));
Expand Down
Loading