@@ -30,6 +30,13 @@ type WrapperHarness = {
3030 readonly ghLogPath : string
3131}
3232
33+ const expectedPlanToGitRuns = (
34+ repoDir : string ,
35+ commands : ReadonlyArray < string > ,
36+ targetRepo = "org/repo"
37+ ) : ReadonlyArray < string > =>
38+ commands . flatMap ( ( command ) => [ `${ repoDir } \ttarget-repo:${ targetRepo } ` , `${ repoDir } \t${ command } ` ] )
39+
3340const fakeGitScript = `#!/usr/bin/env bash
3441set -euo pipefail
3542
@@ -168,50 +175,14 @@ exit 0
168175const fakePlanToGitScript = `#!/usr/bin/env bash
169176set -euo pipefail
170177
171- fake_effective_origin_url() {
172- local origin_url="\${FAKE_GIT_ORIGIN_URL:-https://github.com/org/repo.git}"
173- local config_index=0
174- local key_var=""
175- local value_var=""
176- local key=""
177- local value=""
178- local base_url=""
179- local suffix=""
180-
181- if [[ -n "\${GIT_CONFIG_COUNT:-}" && "\${GIT_CONFIG_COUNT}" =~ ^[0-9]+$ ]]; then
182- while [[ "$config_index" -lt "$GIT_CONFIG_COUNT" ]]; do
183- key_var="GIT_CONFIG_KEY_\${config_index}"
184- value_var="GIT_CONFIG_VALUE_\${config_index}"
185- key="\${!key_var:-}"
186- value="\${!value_var:-}"
187- if [[ "$key" == url.*.insteadOf && -n "$value" && "$origin_url" == "$value"* ]]; then
188- base_url="\${key#url.}"
189- base_url="\${base_url%.insteadOf}"
190- suffix="\${origin_url#"$value"}"
191- printf '%s\\n' "\${base_url}\${suffix}"
192- return 0
193- fi
194- config_index=$((config_index + 1))
195- done
196- fi
197-
198- printf '%s\\n' "$origin_url"
199- }
200-
201178if [[ "\${1:-}" == "sync" && "\${2:-}" == "--help" ]]; then
202179 printf '%s\\n' "--pr <PR>"
203180 exit 0
204181fi
205182
206183if [[ -n "\${FAKE_PLAN_TO_GIT_LOG_PATH:-}" ]]; then
207- if [[ -n "\${GIT_CONFIG_COUNT:-}" && "\${GIT_CONFIG_COUNT}" =~ ^[0-9]+$ ]]; then
208- config_index=0
209- while [[ "$config_index" -lt "$GIT_CONFIG_COUNT" ]]; do
210- key_var="GIT_CONFIG_KEY_\${config_index}"
211- value_var="GIT_CONFIG_VALUE_\${config_index}"
212- printf '%s\\tgit-config:%s=%s\\n' "$PWD" "\${!key_var:-}" "\${!value_var:-}" >> "$FAKE_PLAN_TO_GIT_LOG_PATH"
213- config_index=$((config_index + 1))
214- done
184+ if [[ -n "\${PLAN_TO_GIT_REPO:-}" ]]; then
185+ printf '%s\\ttarget-repo:%s\\n' "$PWD" "$PLAN_TO_GIT_REPO" >> "$FAKE_PLAN_TO_GIT_LOG_PATH"
215186 fi
216187 printf '%s\\t%s\\n' "$PWD" "$*" >> "$FAKE_PLAN_TO_GIT_LOG_PATH"
217188fi
@@ -224,10 +195,9 @@ if [[ "\${1:-}" != "import-codex" && "\${1:-}" != "import-claude" && "\${1:-}" !
224195 exit 127
225196fi
226197
227- if [[ "\${1:-}" == "sync" && "\${2:-}" == "--pr" && -n "\${FAKE_PLAN_TO_GIT_EXPECT_EFFECTIVE_ORIGIN_URL:-}" ]]; then
228- effective_origin_url="$(fake_effective_origin_url)"
229- if [[ "$effective_origin_url" != "$FAKE_PLAN_TO_GIT_EXPECT_EFFECTIVE_ORIGIN_URL" ]]; then
230- echo "fakePlanToGit: expected effective origin $FAKE_PLAN_TO_GIT_EXPECT_EFFECTIVE_ORIGIN_URL, got $effective_origin_url" >&2
198+ if [[ "\${1:-}" == "sync" && "\${2:-}" == "--pr" && -n "\${FAKE_PLAN_TO_GIT_EXPECT_TARGET_REPO:-}" ]]; then
199+ if [[ "\${PLAN_TO_GIT_REPO:-}" != "$FAKE_PLAN_TO_GIT_EXPECT_TARGET_REPO" ]]; then
200+ echo "fakePlanToGit: expected target repo $FAKE_PLAN_TO_GIT_EXPECT_TARGET_REPO, got \${PLAN_TO_GIT_REPO:-<unset>}" >&2
231201 exit 44
232202 fi
233203fi
@@ -442,11 +412,9 @@ describe("git post-push wrapper", () => {
442412 expect ( nodeCwd ) . toEqual ( [ harness . repoDir ] )
443413 expect ( nodeRepoRoot ) . toEqual ( [ harness . repoDir ] )
444414 expect ( nodeScript ) . toEqual ( [ "backup --verbose --background --require-comment" ] )
445- expect ( planToGit ) . toEqual ( [
446- `${ harness . repoDir } \timport-codex --no-sync` ,
447- `${ harness . repoDir } \timport-claude --no-sync` ,
448- `${ harness . repoDir } \tsync`
449- ] )
415+ expect ( planToGit ) . toEqual (
416+ expectedPlanToGitRuns ( harness . repoDir , [ "import-codex --no-sync" , "import-claude --no-sync" , "sync" ] )
417+ )
450418 expect ( gh ) . toContain ( `${ harness . repoDir } \tpr create --repo org/repo --base main --head issue-375 --fill` )
451419 } )
452420 ) . pipe ( Effect . provide ( NodeContext . layer ) ) )
@@ -466,11 +434,9 @@ describe("git post-push wrapper", () => {
466434 expect ( nodeCwd ) . toEqual ( [ harness . repoDir ] )
467435 expect ( nodeRepoRoot ) . toEqual ( [ harness . repoDir ] )
468436 expect ( nodeScript ) . toEqual ( [ "backup --verbose --background --require-comment" ] )
469- expect ( planToGit ) . toEqual ( [
470- `${ harness . repoDir } \timport-codex --no-sync` ,
471- `${ harness . repoDir } \timport-claude --no-sync` ,
472- `${ harness . repoDir } \tsync`
473- ] )
437+ expect ( planToGit ) . toEqual (
438+ expectedPlanToGitRuns ( harness . repoDir , [ "import-codex --no-sync" , "import-claude --no-sync" , "sync" ] )
439+ )
474440 expect ( gh ) . toContain ( `${ harness . repoDir } \tpr create --repo org/repo --base main --head issue-375 --fill` )
475441 expect ( gitLog . some ( ( line ) => line . startsWith ( `${ harness . externalDir } \t-C ${ harness . repoDir } push` ) ) ) . toBe ( true )
476442 } )
@@ -559,7 +525,7 @@ describe("git post-push wrapper", () => {
559525 const gh = yield * _ ( readLogLines ( harness . ghLogPath ) )
560526
561527 expect ( nodeScript ) . toEqual ( [ ] )
562- expect ( planToGit ) . toEqual ( [ ` ${ harness . repoDir } \timport -codex --no-sync` ] )
528+ expect ( planToGit ) . toEqual ( expectedPlanToGitRuns ( harness . repoDir , [ "import -codex --no-sync" ] ) )
563529 expect ( gh ) . toContain ( `${ harness . repoDir } \tpr create --repo org/repo --base main --head issue-375 --fill` )
564530 } )
565531 ) . pipe ( Effect . provide ( NodeContext . layer ) ) )
@@ -578,11 +544,9 @@ describe("git post-push wrapper", () => {
578544 const planToGit = yield * _ ( readLogLines ( harness . planToGitLogPath ) )
579545
580546 expect ( nodeScript ) . toEqual ( [ "backup --verbose --background --require-comment" ] )
581- expect ( planToGit ) . toEqual ( [
582- `${ harness . repoDir } \timport-codex --no-sync` ,
583- `${ harness . repoDir } \timport-claude --no-sync` ,
584- `${ harness . repoDir } \tsync`
585- ] )
547+ expect ( planToGit ) . toEqual (
548+ expectedPlanToGitRuns ( harness . repoDir , [ "import-codex --no-sync" , "import-claude --no-sync" , "sync" ] )
549+ )
586550 } )
587551 ) . pipe ( Effect . provide ( NodeContext . layer ) ) )
588552
@@ -600,11 +564,9 @@ describe("git post-push wrapper", () => {
600564 const gh = yield * _ ( readLogLines ( harness . ghLogPath ) )
601565
602566 expect ( nodeScript ) . toEqual ( [ "backup --verbose --background --require-comment" ] )
603- expect ( planToGit ) . toEqual ( [
604- `${ harness . repoDir } \timport-codex --no-sync` ,
605- `${ harness . repoDir } \timport-claude --no-sync` ,
606- `${ harness . repoDir } \tsync`
607- ] )
567+ expect ( planToGit ) . toEqual (
568+ expectedPlanToGitRuns ( harness . repoDir , [ "import-codex --no-sync" , "import-claude --no-sync" , "sync" ] )
569+ )
608570 expect ( gh ) . toContain ( `${ harness . repoDir } \tpr list --repo org/repo --state open --head issue-375 --json url --jq .[0].url // ""` )
609571 expect ( gh . some ( ( line ) => line . includes ( "pr create" ) ) ) . toBe ( false )
610572 } )
@@ -631,7 +593,7 @@ describe("git post-push wrapper", () => {
631593 } )
632594 ) . pipe ( Effect . provide ( NodeContext . layer ) ) )
633595
634- it . effect ( "syncs explicit PR plans against upstream when origin is a fork" , ( ) =>
596+ it . effect ( "syncs explicit PR plans against upstream target repo when origin is a fork" , ( ) =>
635597 withHarness ( ( harness ) =>
636598 Effect . gen ( function * ( _ ) {
637599 yield * _ (
@@ -641,25 +603,19 @@ describe("git post-push wrapper", () => {
641603 FAKE_GH_OPEN_PR_URL : "https://github.com/org/repo/pull/375" ,
642604 FAKE_GIT_ORIGIN_URL : "https://github.com/me/repo.git" ,
643605 FAKE_GIT_UPSTREAM_URL : "https://github.com/org/repo.git" ,
644- FAKE_PLAN_TO_GIT_EXPECT_EFFECTIVE_ORIGIN_URL : "https://github.com/ org/repo.git "
606+ FAKE_PLAN_TO_GIT_EXPECT_TARGET_REPO : "org/repo"
645607 }
646608 } )
647609 )
648610
649611 const nodeScript = yield * _ ( readLogLines ( harness . nodeScriptLogPath ) )
650612 const planToGit = yield * _ ( readLogLines ( harness . planToGitLogPath ) )
651613 const gh = yield * _ ( readLogLines ( harness . ghLogPath ) )
652- const scopedRepoConfig = `${ harness . repoDir } \tgit-config:url.https://github.com/org/repo.git.insteadOf=https://github.com/me/repo.git`
653614
654615 expect ( nodeScript ) . toEqual ( [ "backup --verbose --background --require-comment" ] )
655- expect ( planToGit ) . toEqual ( [
656- scopedRepoConfig ,
657- `${ harness . repoDir } \timport-codex --no-sync` ,
658- scopedRepoConfig ,
659- `${ harness . repoDir } \timport-claude --no-sync` ,
660- scopedRepoConfig ,
661- `${ harness . repoDir } \tsync --pr 375`
662- ] )
616+ expect ( planToGit ) . toEqual (
617+ expectedPlanToGitRuns ( harness . repoDir , [ "import-codex --no-sync" , "import-claude --no-sync" , "sync --pr 375" ] )
618+ )
663619 expect ( gh ) . toContain ( `${ harness . repoDir } \tpr list --repo org/repo --state open --head me:issue-375 --json url --jq .[0].url // ""` )
664620 expect ( gh . some ( ( line ) => line . includes ( "pr create" ) ) ) . toBe ( false )
665621 } )
0 commit comments