Skip to content

Commit e5c8a59

Browse files
committed
Merge remote-tracking branch 'origin/master' into make-issue-relative-work-home
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2 parents ba028ea + 95bfc77 commit e5c8a59

18 files changed

Lines changed: 2224 additions & 1571 deletions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
firebase-admin
22
pyyaml
3-
tclint==0.7.0
3+
tclint==0.9.0
44
yamlfix==1.19.1

‎.github/requirements/requirements_lock.txt‎

Lines changed: 799 additions & 647 deletions
Large diffs are not rendered by default.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Test Claude Docker scripts
2+
3+
on:
4+
push:
5+
branches: [master]
6+
paths: &claude_paths
7+
- 'claude.sh'
8+
- 'env.sh'
9+
- 'docker/*claude*.sh'
10+
- '.github/workflows/github-actions-claude-shell-test.yml'
11+
pull_request:
12+
paths: *claude_paths
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
shell-tests:
19+
# The Git fixture creates /workspace and /home/claude-user on a fresh VM.
20+
runs-on: ubuntu-26.04
21+
timeout-minutes: 10
22+
steps:
23+
- name: Check out repository
24+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
25+
with:
26+
persist-credentials: false
27+
- name: Test wrapper arguments
28+
run: bash docker/test-claude-sh.sh
29+
- name: Pull container test image
30+
run: docker pull openroad/flow-ubuntu26.04-dev:latest
31+
- name: Test entrypoint account and settings
32+
run: bash docker/test-claude-entrypoint.sh
33+
- name: Test Git with reserved host paths
34+
run: |
35+
sudo mkdir /workspace /home/claude-user
36+
sudo chown "$(id -u):$(id -g)" /workspace /home/claude-user
37+
bash docker/test-claude-worktree-paths.sh

‎.github/workflows/github-actions-cron-update-OR.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
git pull
3030
- if: "steps.remote-update.outputs.has_update != ''"
3131
name: Create Draft PR
32-
uses: peter-evans/create-pull-request@15733dbdfeedb4f7fdb73d13c6f5ac83b710fab8 # v8.1.2
32+
uses: peter-evans/create-pull-request@3ffccacd46053766916f087ce41d627c0b8cf2d1 # v8.1.3
3333
with:
3434
token: ${{ github.token }}
3535
signoff: true

‎.github/workflows/github-actions-cron-update-yosys.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
git checkout ${latesttag}
3333
- if: "steps.remote-update.outputs.has_update != ''"
3434
name: Create Draft PR
35-
uses: peter-evans/create-pull-request@15733dbdfeedb4f7fdb73d13c6f5ac83b710fab8 # v8.1.2
35+
uses: peter-evans/create-pull-request@3ffccacd46053766916f087ce41d627c0b8cf2d1 # v8.1.3
3636
with:
3737
token: ${{ github.token }}
3838
signoff: true

‎.github/workflows/github-actions-update-rules.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
git push origin "HEAD:refs/pull/${{ github.event.client_payload.branch }}/head"
6363
- if: "steps.remote-update.outputs.has_update == 'true' && github.event.client_payload.branch == 'master'"
6464
name: Create Draft PR
65-
uses: peter-evans/create-pull-request@15733dbdfeedb4f7fdb73d13c6f5ac83b710fab8 # v8.1.2
65+
uses: peter-evans/create-pull-request@3ffccacd46053766916f087ce41d627c0b8cf2d1 # v8.1.3
6666
with:
6767
token: ${{ github.token }}
6868
signoff: true

‎claude.sh‎

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ CONTAINER_HOME="/home/claude-user"
8686

8787
# --- Git data of a worktree ---
8888
# A worktree's .git file, and the .git files of its submodules, point to the
89-
# main checkout's git directory by host path, absolute or relative. Mount that
90-
# directory and the worktree at their host paths, and start in the worktree's
91-
# host path, so these links resolve in the container. /workspace stays.
89+
# main checkout's git directory by absolute or relative paths. Keep their
90+
# relative layout so links from submodules resolve in the container.
9291
HOST_DIR=$(cd "${SCRIPT_DIR}" && pwd -P)
9392
CONTAINER_WORKDIR=/workspace
9493
GIT_TOP=""
@@ -106,21 +105,37 @@ outside_container_paths() {
106105
}
107106

108107
GIT_MOUNTS=()
108+
GIT_LINK_DIR=""
109+
mount_prefix=""
110+
# The existing checkout mount already preserves an exact /workspace path.
111+
if { [[ "${HOST_DIR}" != /workspace ]] && ! outside_container_paths "${HOST_DIR}"; } ||
112+
! outside_container_paths "${GIT_COMMON_DIR}"; then
113+
mount_prefix=/tmp/claude-worktree
114+
fi
115+
109116
# Only for the top of a checkout: a plain folder inside another repository
110-
# must not get that repository's .git.
117+
# must not get that repository's .git. A gitfile also needs relocation when
118+
# it points inside the checkout but the /workspace mount hides the host path.
111119
if [[ "${GIT_TOP}" == "${HOST_DIR}" && -n "${GIT_COMMON_DIR}" &&
112-
"${GIT_COMMON_DIR}/" != "${HOST_DIR}/"* ]]; then
113-
if outside_container_paths "${HOST_DIR}" &&
114-
outside_container_paths "${GIT_COMMON_DIR}"; then
115-
GIT_MOUNTS=(
116-
-v "${HOST_DIR}:${HOST_DIR}"
117-
-v "${GIT_COMMON_DIR}:${GIT_COMMON_DIR}"
118-
)
119-
CONTAINER_WORKDIR=${HOST_DIR}
120-
else
121-
echo "Warning: ${HOST_DIR} and its git data in ${GIT_COMMON_DIR} cannot" \
122-
"both be mounted at their host paths, because one of them is under" \
123-
"/workspace or ${CONTAINER_HOME}. Git does not work in the container." >&2
120+
( "${GIT_COMMON_DIR}/" != "${HOST_DIR}/"* ||
121+
( -n "${mount_prefix}" && "${HOST_DIR}" != /workspace && -f "${HOST_DIR}/.git" ) ) ]]; then
122+
CONTAINER_WORKDIR="${mount_prefix}${HOST_DIR}"
123+
if [[ "${CONTAINER_WORKDIR}" != /workspace ]]; then
124+
GIT_MOUNTS+=(-v "${HOST_DIR}:${CONTAINER_WORKDIR}")
125+
fi
126+
if [[ "${GIT_COMMON_DIR}/" != "${HOST_DIR}/"* ]]; then
127+
GIT_MOUNTS+=(-v "${GIT_COMMON_DIR}:${mount_prefix}${GIT_COMMON_DIR}")
128+
fi
129+
if [[ -n "${mount_prefix}" && -f "${HOST_DIR}/.git" ]]; then
130+
# Overlay the gitfile so its absolute target uses the new prefix.
131+
# Git still writes to the shared metadata through the directory mount.
132+
git_dir=$(git -C "${HOST_DIR}" rev-parse --absolute-git-dir)
133+
git_dir=$(cd "${git_dir}" && pwd -P)
134+
# Keep the source on a path already shared with the container engine.
135+
GIT_LINK_DIR=$(mktemp -d "${git_dir}/claude-link.XXXXXX")
136+
trap 'rm -rf -- "${GIT_LINK_DIR}"' EXIT
137+
printf 'gitdir: %s%s\n' "${mount_prefix}" "${git_dir}" > "${GIT_LINK_DIR}/gitfile"
138+
GIT_MOUNTS+=(-v "${GIT_LINK_DIR}/gitfile:${CONTAINER_WORKDIR}/.git:ro")
124139
fi
125140
fi
126141

@@ -197,13 +212,24 @@ DOCKER_RUN_ARGS+=(-v "${BAZEL_CACHE_DIR}:${CONTAINER_HOME}/.cache/bazel")
197212

198213
# --- Run ---
199214
if [[ "${SHELL_MODE}" -eq 1 ]]; then
200-
exec docker run \
201-
"${DOCKER_RUN_ARGS[@]}" \
202-
"${CLAUDE_IMAGE}" \
203-
bash
215+
command=(bash)
204216
else
205-
exec docker run \
206-
"${DOCKER_RUN_ARGS[@]}" \
207-
"${CLAUDE_IMAGE}" \
208-
claude --dangerously-skip-permissions "${CLAUDE_ARGS[@]}"
217+
command=(claude --dangerously-skip-permissions "${CLAUDE_ARGS[@]}")
209218
fi
219+
220+
if [[ -z "${GIT_LINK_DIR}" ]]; then
221+
exec docker run "${DOCKER_RUN_ARGS[@]}" "${CLAUDE_IMAGE}" "${command[@]}"
222+
fi
223+
224+
# Wait for Docker before removing the temporary bind source. Keep stdin open
225+
# and pass signals sent to the wrapper through to the Docker client.
226+
docker run "${DOCKER_RUN_ARGS[@]}" "${CLAUDE_IMAGE}" "${command[@]}" <&0 &
227+
docker_pid=$!
228+
forward_signal() {
229+
kill -s "$1" "${docker_pid}" 2>/dev/null || return 0
230+
wait "${docker_pid}" || true
231+
}
232+
trap 'forward_signal HUP' HUP
233+
trap 'forward_signal INT' INT
234+
trap 'forward_signal TERM' TERM
235+
wait "${docker_pid}"
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#!/usr/bin/env bash
2+
# Run only on a disposable Linux host with empty, writable /workspace and
3+
# /home/claude-user directories. The test needs Git, Bash and a container engine.
4+
set -euo pipefail
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
7+
for dir in /workspace /home/claude-user; do
8+
if [[ ! -d "${dir}" || ! -w "${dir}" || -n "$(ls -A "${dir}")" ]]; then
9+
echo "Test requires an empty, writable ${dir}" >&2
10+
exit 1
11+
fi
12+
done
13+
14+
tmp=$(mktemp -d)
15+
workspace_fixture=$(mktemp -d /workspace/claude-test.XXXXXX)
16+
home_fixture=$(mktemp -d /home/claude-user/claude-test.XXXXXX)
17+
trap 'rm -rf "${tmp}" "${workspace_fixture}" "${home_fixture}"' EXIT
18+
19+
export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null
20+
export GIT_AUTHOR_NAME=test GIT_AUTHOR_EMAIL=test@example.invalid
21+
export GIT_COMMITTER_NAME=test GIT_COMMITTER_EMAIL=test@example.invalid
22+
# Resolve the real engine before adding the test shim to PATH.
23+
TEST_ENGINE=$(command -v "${CONTAINER_ENGINE:-docker}")
24+
export TEST_ENGINE
25+
export TEST_ENGINE_HOME="${HOME}"
26+
export TEST_ENTRYPOINT="${SCRIPT_DIR}/claude-entrypoint.sh"
27+
export TEST_SETUP="${tmp}/entrypoint"
28+
image="${TEST_IMAGE:-openroad/flow-ubuntu26.04-dev:latest}"
29+
30+
mkdir -p "${tmp}/bin" "${tmp}/settings/.claude" "${tmp}/settings/.cache/bazel-claude"
31+
cat > "${TEST_SETUP}" <<'SH'
32+
#!/usr/bin/env bash
33+
set -e
34+
mkdir -p /etc/sudoers.d
35+
exec /test-entrypoint.sh "$@"
36+
SH
37+
cat > "${tmp}/bin/docker" <<'SH'
38+
#!/usr/bin/env bash
39+
engine_args=()
40+
if [[ "${TEST_ENGINE##*/}" == podman ]]; then
41+
export HOME="${TEST_ENGINE_HOME}"
42+
engine_args+=(--userns keep-id --security-opt label=disable)
43+
fi
44+
case "$1" in
45+
image) exec "${TEST_ENGINE}" "$@" ;;
46+
run)
47+
shift
48+
exec "${TEST_ENGINE}" run "${engine_args[@]}" --user 0:0 --network none \
49+
--cap-drop ALL --cap-add CHOWN --cap-add SETUID --cap-add SETGID \
50+
--cap-add DAC_OVERRIDE --security-opt no-new-privileges \
51+
-v "${TEST_ENTRYPOINT}:/test-entrypoint.sh:ro" \
52+
-v "${TEST_SETUP}:/test-setup.sh:ro" \
53+
--entrypoint /test-setup.sh "$@"
54+
;;
55+
*) exit 1 ;;
56+
esac
57+
SH
58+
chmod +x "${TEST_SETUP}" "${tmp}/bin/docker"
59+
60+
cat > "${tmp}/settings/.gitconfig" <<'CONFIG'
61+
[user]
62+
name = test
63+
email = test@example.invalid
64+
CONFIG
65+
echo saved > "${tmp}/settings/.claude.json"
66+
67+
git init -q "${tmp}/module"
68+
echo module > "${tmp}/module/content"
69+
git -C "${tmp}/module" add content
70+
git -C "${tmp}/module" commit -qm module
71+
72+
make_main() {
73+
git init -q "$1"
74+
cp "${SCRIPT_DIR}/../claude.sh" "$1/claude.sh"
75+
echo initial > "$1/content"
76+
git -C "$1" -c protocol.file.allow=always submodule add -q "${tmp}/module" module
77+
git -C "$1" add claude.sh content
78+
git -C "$1" commit -qm initial
79+
}
80+
81+
make_worktree() {
82+
git -C "$1" worktree add --detach -q "$2"
83+
git -C "$2" -c protocol.file.allow=always submodule update --init -q
84+
}
85+
86+
run_case() {
87+
local checkout=$1 name=$2 original original_module ref git_dir
88+
original=$(cat "${checkout}/.git") || return 1
89+
original_module=$(cat "${checkout}/module/.git") || return 1
90+
git_dir=$(git -C "${checkout}" rev-parse --absolute-git-dir) || return 1
91+
echo fixture > "${tmp}/settings/.claude/settings.json"
92+
rm -f "${tmp}/settings/.cache/bazel-claude/marker"
93+
if ! env -u SSH_AUTH_SOCK -u ANTHROPIC_API_KEY -u AWS_ACCESS_KEY_ID \
94+
-u AWS_SECRET_ACCESS_KEY -u GOOGLE_APPLICATION_CREDENTIALS -u BAZEL_CACHE_DIR \
95+
HOME="${tmp}/settings" PATH="${tmp}/bin:${PATH}" \
96+
bash "${checkout}/claude.sh" --shell --image "${image}" --name "claude-git-test-$$" <<'SH'
97+
set -eu
98+
test "$(git rev-parse --show-toplevel)" = "$(pwd -P)"
99+
test "$(git -C module rev-parse --show-toplevel)" = "$(pwd -P)/module"
100+
status=$(git status --porcelain)
101+
test -z "${status}"
102+
test "$(git -C module show HEAD:content)" = module
103+
git switch -qc "test-$(basename "$(git rev-parse --absolute-git-dir)")"
104+
echo modified > content
105+
git add content
106+
git -c commit.gpgsign=false commit -qm modified
107+
test "$(cat /workspace/content)" = modified
108+
test "$(git config --get gc.worktreePruneExpire)" = never
109+
test "$(cat "${HOME}/.claude/settings.json")" = fixture
110+
test "$(cat "${HOME}/.claude.json")" = saved
111+
if (echo changed >> "${HOME}/.gitconfig") 2>/dev/null; then
112+
exit 1
113+
fi
114+
echo updated > "${HOME}/.claude/settings.json"
115+
touch "${HOME}/.cache/bazel/marker"
116+
SH
117+
then
118+
echo "FAIL: ${name}" >&2
119+
return 1
120+
fi
121+
ref=$(git -C "${checkout}" symbolic-ref HEAD) || return 1
122+
if compgen -G "${git_dir}/claude-link.*" > /dev/null; then
123+
echo "FAIL: ${name}: temporary Git pointer was left behind" >&2
124+
return 1
125+
fi
126+
if [[ "$(cat "${checkout}/.git")" != "${original}" ||
127+
"$(cat "${checkout}/module/.git")" != "${original_module}" ||
128+
"$(git -C "${checkout}" show "${ref}:content")" != modified ||
129+
"$(cat "${tmp}/settings/.claude/settings.json")" != updated ||
130+
! -f "${tmp}/settings/.cache/bazel-claude/marker" ]]; then
131+
echo "FAIL: ${name}: unexpected host state" >&2
132+
return 1
133+
fi
134+
echo "PASS: ${name}"
135+
}
136+
137+
make_main "${tmp}/main"
138+
make_main "${workspace_fixture}/main"
139+
make_main "${home_fixture}/main"
140+
make_worktree "${tmp}/main" "${workspace_fixture}/worktree"
141+
make_worktree "${tmp}/main" "${home_fixture}/worktree"
142+
git -C "${workspace_fixture}/main" -c worktree.useRelativePaths=true \
143+
worktree add --detach -q "${tmp}/workspace-data"
144+
git -C "${tmp}/workspace-data" -c protocol.file.allow=always submodule update --init -q
145+
make_worktree "${home_fixture}/main" "${tmp}/home-data"
146+
147+
# A linked checkout can contain its main repository after the main
148+
# repository moves and Git repairs the links.
149+
nested_checkout="${workspace_fixture}/nested"
150+
make_main "${tmp}/nested-main"
151+
git -C "${tmp}/nested-main" worktree add --detach -q "${nested_checkout}"
152+
mv "${tmp}/nested-main" "${nested_checkout}/main"
153+
git -C "${nested_checkout}/main" worktree repair "${nested_checkout}"
154+
echo /main/ >> "${nested_checkout}/main/.git/info/exclude"
155+
git -C "${nested_checkout}" -c protocol.file.allow=always submodule update --init -q
156+
157+
failed=0
158+
run_case "${workspace_fixture}/worktree" "worktree under /workspace" || failed=1
159+
run_case "${home_fixture}/worktree" "worktree under /home/claude-user" || failed=1
160+
run_case "${tmp}/workspace-data" "Git data under /workspace" || failed=1
161+
run_case "${tmp}/home-data" "Git data under /home/claude-user" || failed=1
162+
run_case "${nested_checkout}" "Git data inside the worktree" || failed=1
163+
164+
# Use /workspace itself only after removing this test's nested fixtures.
165+
rm -rf "${workspace_fixture}"
166+
make_worktree "${tmp}/main" /workspace
167+
run_case /workspace "worktree at /workspace" || failed=1
168+
# The caller provides /workspace. Remove the fixture files and let the exit
169+
# trap remove the temporary repository that stores their Git data.
170+
rm -rf -- /workspace/{.git,.gitmodules,claude.sh,content,module}
171+
workspace_entries=$(ls -A /workspace)
172+
test -z "${workspace_entries}"
173+
exit "${failed}"

‎docs/requirements.in‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sphinx-external-toc==1.1.0
44
sphinx~=9.1.0
55
docutils>=0.22,<0.23
66
sphinx-autobuild
7-
myst-parser~=5.1.0
7+
myst-parser~=5.2.0
88
# sphinx-book-theme 1.4.0 requires pydata-sphinx-theme 0.20.0 exactly.
99
sphinx-book-theme==1.4.0
1010
pydata-sphinx-theme==0.20.0

0 commit comments

Comments
 (0)