Skip to content

Commit 1153e29

Browse files
authored
Merge pull request #1875 from Automattic/fix/1874-publication-repo-casing
Accept canonical GitHub repository casing
2 parents 65fe008 + c32b04b commit 1153e29

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

.github/scripts/run-agent-task/execute-native-agent-task.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ function validPublication(value, targetRepo) {
283283
&& publication.success === true
284284
&& publication.status === "published"
285285
&& /^https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/pull\/\d+\/?$/.test(url)
286-
&& url.startsWith(`https://github.com/${targetRepo}/pull/`)
286+
&& url.toLowerCase().startsWith(`https://github.com/${targetRepo.toLowerCase()}/pull/`)
287287
}
288288

289289
async function verifyPublishedPullRequest(publication, targetRepo, cwd) {
@@ -297,7 +297,7 @@ async function verifyPublishedPullRequest(publication, targetRepo, cwd) {
297297
const pullRequest = JSON.parse(response.stdout)
298298
return {
299299
valid: pullRequest?.html_url === record(publication).pull_request?.url
300-
&& pullRequest?.base?.repo?.full_name === targetRepo,
300+
&& string(pullRequest?.base?.repo?.full_name).toLowerCase() === targetRepo.toLowerCase(),
301301
error: "Published pull request did not resolve to the target repository.",
302302
}
303303
} catch {

tests/execute-native-agent-task-lifecycle.test.mjs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const execFileAsync = promisify(execFile)
1414
async function run(mode = "success") {
1515
const temp = await mkdtemp(join(tmpdir(), "wp-codebox-native-lifecycle-"))
1616
const workspace = join(temp, "workspace")
17+
const targetRepo = mode === "canonical-casing" ? "automattic/build-with-wordpress" : "owner/repo"
18+
const publicationRepo = mode === "canonical-casing"
19+
? "Automattic/build-with-wordpress"
20+
: mode === "different-repo" ? "other/repo" : targetRepo
1721
await mkdir(join(workspace, ".codebox"), { recursive: true })
1822
await writeFile(join(workspace, "README.md"), "OPENAI_API_KEY\nbefore\n")
1923

@@ -28,12 +32,12 @@ async function run(mode = "success") {
2832
},
2933
runtime_sources: [],
3034
workload: { id: "run-1", label: "Update" },
31-
target_repo: "owner/repo",
35+
target_repo: targetRepo,
3236
prompt: "Edit README using workspace_read and workspace_edit.",
3337
writable_paths: mode === "deny" ? "src/**" : "README.md",
3438
runner_workspace: {
3539
enabled: true,
36-
repo: "owner/repo",
40+
repo: targetRepo,
3741
base: "main",
3842
branch_prefix: "wp-codebox/agent-task/",
3943
},
@@ -44,9 +48,9 @@ async function run(mode = "success") {
4448
drift_checks: [{ command: "echo drift >> .codebox/order" }],
4549
success: { requires_pr: mode !== "no-op-maintenance" },
4650
access: {
47-
caller_repo: "owner/repo",
48-
allowed_repos: ["owner/repo"],
49-
access_token_repos: ["owner/repo"],
51+
caller_repo: targetRepo,
52+
allowed_repos: [targetRepo],
53+
access_token_repos: [targetRepo],
5054
},
5155
limits: { max_turns: 1, time_budget_ms: 1000 },
5256
artifacts: { expected: [], declarations: [] },
@@ -127,16 +131,16 @@ export async function publishRunnerWorkspace({ testHook }) {
127131
success: true,
128132
status: "published",
129133
backend: "fixture",
130-
pull_request: { url: "https://github.com/owner/repo/pull/1", reused: false, opened: true },
134+
pull_request: { url: ${JSON.stringify(`https://github.com/${publicationRepo}/pull/1`)}, reused: false, opened: true },
131135
}
132136
}
133137
`)
134138

135139
const gh = join(temp, "gh")
136140
await writeFile(gh, `#!/usr/bin/env node
137141
process.stdout.write(JSON.stringify({
138-
html_url: "https://github.com/owner/repo/pull/1",
139-
base: { repo: { full_name: "owner/repo" } },
142+
html_url: ${JSON.stringify(`https://github.com/${publicationRepo}/pull/1`)},
143+
base: { repo: { full_name: ${JSON.stringify(publicationRepo)} } },
140144
}))
141145
`)
142146
await chmod(gh, 0o755)
@@ -190,6 +194,15 @@ assert.equal(success.result.runtime_result.agent_runtime_diagnostics.prepared_pa
190194
assert.equal(success.result.runtime_result.agent_runtime_diagnostics.sandbox_workspace.mounts[0].target, "/workspace")
191195
assert.equal(success.result.runtime_result.agent_runtime_diagnostics.local_executor_root, "/workspace")
192196

197+
const canonicalCasing = await run("canonical-casing")
198+
assert.equal(canonicalCasing.code, 0, `${canonicalCasing.stderr}\n${JSON.stringify(canonicalCasing.result)}`)
199+
assert.equal(canonicalCasing.result.publication_verification.valid, true)
200+
201+
const differentRepository = await run("different-repo")
202+
assert.equal(differentRepository.code, 1)
203+
assert.equal(differentRepository.result.publication_verification.valid, false)
204+
assert.match(differentRepository.result.failure.message, /valid canonical pull-request result/)
205+
193206
const failedVerification = await run("verify-fail")
194207
assert.equal(failedVerification.code, 1)
195208
assert(!failedVerification.order.includes("publish"))

0 commit comments

Comments
 (0)