Skip to content

Commit 611afeb

Browse files
committed
fix(lib): harden issue workspace env reset flow
1 parent 8b8dc6c commit 611afeb

3 files changed

Lines changed: 22 additions & 20 deletions

File tree

packages/lib/src/core/templates-entrypoint/codex.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,21 @@ if [[ "$REPO_REF" == issue-* ]]; then
150150
if [[ "$REPO_URL" == https://github.com/* ]]; then
151151
ISSUE_REPO="$(printf "%s" "$REPO_URL" | sed -E 's#^https://github.com/##; s#[.]git$##; s#/*$##')"
152152
if [[ -n "$ISSUE_REPO" ]]; then
153-
ISSUE_URL="https://github.com/\${ISSUE_REPO}/issues/\${ISSUE_ID}"
153+
ISSUE_URL="https://github.com/$ISSUE_REPO/issues/$ISSUE_ID"
154154
fi
155155
fi
156156
if [[ -n "$ISSUE_URL" ]]; then
157-
WORKSPACE_INFO_LINE="Контекст workspace: issue #\${ISSUE_ID} (\${ISSUE_URL})"
157+
WORKSPACE_INFO_LINE="Контекст workspace: issue #$ISSUE_ID ($ISSUE_URL)"
158158
else
159-
WORKSPACE_INFO_LINE="Контекст workspace: issue #\${ISSUE_ID}"
159+
WORKSPACE_INFO_LINE="Контекст workspace: issue #$ISSUE_ID"
160160
fi
161161
ISSUE_AGENTS_HINT_LINE="Issue AGENTS.md: __TARGET_DIR__/AGENTS.md"
162162
elif [[ "$REPO_REF" == refs/pull/*/head ]]; then
163163
PR_ID="$(printf "%s" "$REPO_REF" | sed -E 's#^refs/pull/([0-9]+)/head$#\1#')"
164164
if [[ -n "$PR_ID" ]]; then
165-
WORKSPACE_INFO_LINE="Контекст workspace: PR #\${PR_ID}"
165+
WORKSPACE_INFO_LINE="Контекст workspace: PR #$PR_ID"
166166
else
167-
WORKSPACE_INFO_LINE="Контекст workspace: pull request (\${REPO_REF})"
167+
WORKSPACE_INFO_LINE="Контекст workspace: pull request ($REPO_REF)"
168168
fi
169169
fi
170170
if [[ ! -f "$AGENTS_PATH" ]]; then

packages/lib/src/core/templates-entrypoint/tasks.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ rm -f "$CLONE_DONE_PATH" "$CLONE_FAIL_PATH"
2121
CLONE_OK=1`
2222

2323
const renderCloneRemotes = (config: TemplateConfig): string =>
24-
`if [[ "$CLONE_OK" -eq 1 && -n "$FORK_REPO_URL" && -d "$TARGET_DIR/.git" ]]; then
25-
AUTH_FORK_URL="$FORK_REPO_URL"
26-
if [[ -n "$GIT_AUTH_TOKEN" && "$FORK_REPO_URL" == https://* ]]; then
27-
AUTH_FORK_URL="$(printf "%s" "$FORK_REPO_URL" | sed "s#^https://#https://\${GIT_AUTH_USER}:\${GIT_AUTH_TOKEN}@#")"
28-
fi
29-
if [[ "$FORK_REPO_URL" != "$REPO_URL" ]]; then
30-
su - ${config.sshUser} -c "cd '$TARGET_DIR' && git remote set-url origin '$AUTH_FORK_URL'" || true
31-
su - ${config.sshUser} -c "cd '$TARGET_DIR' && git remote add upstream '$AUTH_REPO_URL' 2>/dev/null || git remote set-url upstream '$AUTH_REPO_URL'" || true
24+
`if [[ "$CLONE_OK" -eq 1 && -d "$TARGET_DIR/.git" ]]; then
25+
if [[ -n "$FORK_REPO_URL" && "$FORK_REPO_URL" != "$REPO_URL" ]]; then
26+
su - ${config.sshUser} -c "cd '$TARGET_DIR' && git remote set-url origin '$FORK_REPO_URL'" || true
27+
su - ${config.sshUser} -c "cd '$TARGET_DIR' && git remote add upstream '$REPO_URL' 2>/dev/null || git remote set-url upstream '$REPO_URL'" || true
28+
else
29+
su - ${config.sshUser} -c "cd '$TARGET_DIR' && git remote set-url origin '$REPO_URL'" || true
30+
su - ${config.sshUser} -c "cd '$TARGET_DIR' && git remote remove upstream >/dev/null 2>&1 || true" || true
3231
fi
3332
fi`
3433

@@ -97,16 +96,19 @@ const renderIssueWorkspaceAgents = (): string =>
9796
if [[ "$REPO_URL" == https://github.com/* ]]; then
9897
ISSUE_REPO="$(printf "%s" "$REPO_URL" | sed -E 's#^https://github.com/##; s#[.]git$##; s#/*$##')"
9998
if [[ -n "$ISSUE_REPO" ]]; then
100-
ISSUE_URL="https://github.com/\${ISSUE_REPO}/issues/\${ISSUE_ID}"
99+
ISSUE_URL="https://github.com/$ISSUE_REPO/issues/$ISSUE_ID"
101100
fi
102101
fi
102+
if [[ -z "$ISSUE_URL" ]]; then
103+
ISSUE_URL="n/a"
104+
fi
103105
104106
ISSUE_AGENTS_PATH="$TARGET_DIR/AGENTS.md"
105107
if [[ ! -e "$ISSUE_AGENTS_PATH" ]]; then
106108
cat <<EOF > "$ISSUE_AGENTS_PATH"
107109
# docker-git issue workspace
108-
Issue workspace: #\${ISSUE_ID}
109-
Issue URL: \${ISSUE_URL:-n/a}
110+
Issue workspace: #$ISSUE_ID
111+
Issue URL: $ISSUE_URL
110112
Workspace path: $TARGET_DIR
111113
112114
Работай только над этим issue, если пользователь не попросил другое.
@@ -128,11 +130,11 @@ const renderCloneBody = (config: TemplateConfig): string =>
128130
[
129131
renderCloneBodyStart(config),
130132
renderCloneBodyRef(config),
133+
"fi",
131134
"",
132135
renderCloneRemotes(config),
133136
"",
134-
renderIssueWorkspaceAgents(),
135-
"fi"
137+
renderIssueWorkspaceAgents()
136138
].join("\n")
137139

138140
const renderCloneFinalize = (): string =>

packages/lib/src/shell/command-runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ export const runCommandWithExitCodes = <E>(
5555
// FORMAT THEOREM: forall cmd: exitCode(cmd) = n
5656
// PURITY: SHELL
5757
// EFFECT: Effect<number, PlatformError, CommandExecutor>
58-
// INVARIANT: stdout/stderr are inherited
58+
// INVARIANT: stdout/stderr are suppressed for status checks
5959
// COMPLEXITY: O(command)
6060
export const runCommandExitCode = (
6161
spec: RunCommandSpec
6262
): Effect.Effect<number, PlatformError, CommandExecutor.CommandExecutor> =>
6363
Effect.map(
6464
Command.exitCode(
65-
buildCommand(spec, "inherit", "inherit", "inherit")
65+
buildCommand(spec, "pipe", "pipe", "inherit")
6666
),
6767
Number
6868
)

0 commit comments

Comments
 (0)