From 68d1f7918d2167b2aeabf31fab23ca8ad4c3b530 Mon Sep 17 00:00:00 2001 From: Austin Gregg-Smith Date: Sun, 25 Oct 2026 21:33:36 +0000 Subject: [PATCH 1/6] fix: container create failed on a host with no ~/.config/gh devcontainer.json bind-mounts ~/.config/gh and ~/.claude, but init-host.sh created only ~/.claude. docker refuses a bind mount whose source does not exist, so a host that never ran `gh auth login` could not create the container. Children fixed this in their own copies (blooop/dbw@56511c8, blooop/mcp-devtasks@d2942da); a template sync would have taken the fix away again. test/test_devcontainer.py runs init-host.sh with a scratch HOME and checks every ${localEnv:HOME} bind source in devcontainer.json exists after it, so a new mount without a matching mkdir fails CI. --- .devcontainer/claude-code/init-host.sh | 9 ++++-- test/test_devcontainer.py | 42 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 test/test_devcontainer.py diff --git a/.devcontainer/claude-code/init-host.sh b/.devcontainer/claude-code/init-host.sh index 7e123bf..da072a9 100755 --- a/.devcontainer/claude-code/init-host.sh +++ b/.devcontainer/claude-code/init-host.sh @@ -1,6 +1,11 @@ #!/bin/sh -# Initialize Claude Code host directory for devcontainer bind mount +# Create the host directories that devcontainer.json bind-mounts. # This script runs on the HOST before the container is created. +# docker refuses to create the container when a bind source is missing, so a +# host that has never run `gh auth login` (no ~/.config/gh) or never run Claude +# Code (no ~/.claude) could not start the container without this. # mkdir -p is idempotent - it only creates if missing, won't clobber existing. +# Keep this list in step with the ${localEnv:HOME} bind mounts in +# devcontainer.json; test/test_devcontainer.py fails when they drift. -mkdir -p "$HOME/.claude" +mkdir -p "$HOME/.claude" "$HOME/.config/gh" diff --git a/test/test_devcontainer.py b/test/test_devcontainer.py new file mode 100644 index 0000000..bf849f7 --- /dev/null +++ b/test/test_devcontainer.py @@ -0,0 +1,42 @@ +import re +import subprocess +from pathlib import Path + +REPO = Path(__file__).resolve().parent.parent +DEVCONTAINER = REPO / ".devcontainer" + + +def host_bind_sources() -> list[str]: + config = (DEVCONTAINER / "devcontainer.json").read_text(encoding="utf-8") + return re.findall(r"source=\$\{localEnv:HOME\}/([^,]+),[^\"]*type=bind", config) + + +def test_init_host_creates_every_home_bind_source(tmp_path): + """docker refuses to create the container when a bind source is missing.""" + sources = host_bind_sources() + assert sources, "found no ${localEnv:HOME} bind mounts in devcontainer.json" + + subprocess.run( + [str(DEVCONTAINER / "claude-code" / "init-host.sh")], + env={"HOME": str(tmp_path), "PATH": "/usr/bin:/bin"}, + check=True, + ) + + missing = [s for s in sources if not (tmp_path / s).is_dir()] + assert not missing, f"init-host.sh did not create: {missing}" + + +def test_init_host_keeps_existing_dirs(tmp_path): + """A second run must not fail or touch what is already there.""" + gh = tmp_path / ".config" / "gh" + gh.mkdir(parents=True) + (gh / "hosts.yml").write_text("token", encoding="utf-8") + + for _ in range(2): + subprocess.run( + [str(DEVCONTAINER / "claude-code" / "init-host.sh")], + env={"HOME": str(tmp_path), "PATH": "/usr/bin:/bin"}, + check=True, + ) + + assert (gh / "hosts.yml").read_text(encoding="utf-8") == "token" From 59f32c65590fe488ac8aaf69f5c7ff6c048c1f6b Mon Sep 17 00:00:00 2001 From: Austin Gregg-Smith Date: Sun, 25 Oct 2026 21:33:36 +0000 Subject: [PATCH 2/6] docs: say which devcontainer.json comments are template-only The comments named the dev-use-local / dev-use-prebuilt pixi tasks, the Dockerfile and .devcontainer/ci/ as if every repo had them. A child cut down to devcontainer.json + post-create.sh has none of them, and the comment came along on every template sync. Mark those parts as python_template's, and say where the bind-mount sources come from. The commented build block stays: dev-use-local uncomments it. --- .devcontainer/devcontainer.json | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7e26bf5..78f8143 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,7 +1,14 @@ { - // Uses the template's prebuilt image by default for fast startup. - // To build locally: pixi run dev-use-local - // To use this repo's own prebuilt image: pixi run dev-use-prebuilt + // Uses python_template's prebuilt image by default for fast startup. + // + // Template-only: python_template itself also ships .devcontainer/Dockerfile, + // .devcontainer/ci/ (the config its image is built from) and two pixi + // tasks that toggle this block -- `pixi run dev-use-local` (uncomment the + // "build" block below and build from the Dockerfile) and + // `pixi run dev-use-prebuilt` (point "image" at this repo's own image). + // A child repo that kept only devcontainer.json and post-create.sh has + // none of those; there the commented "build" block is inert, and to build + // locally you bring them over from blooop/python_template first. // "build": { // "dockerfile": "Dockerfile", // "context": ".." @@ -9,13 +16,13 @@ "image": "ghcr.io/blooop/python_template/devcontainer:latest", // There is deliberately no "features" block. The claude-code feature is - // already baked into the image above: .devcontainer/ci/devcontainer.json, - // which is the config CI builds that image from, declares - // "../claude-code". Declaring it again here made the devcontainer spec - // build a derived image on the first launch of every branch, reinstalling - // something the pulled image already carried -- so the "prebuilt image for - // fast startup" above still paid for a build. With this block gone the - // launch is a pull and nothing else. + // already baked into the image above: python_template's + // .devcontainer/ci/devcontainer.json, which is the config its CI builds + // that image from, declares "../claude-code". Declaring it again here + // made the devcontainer spec build a derived image on the first launch of + // every branch, reinstalling something the pulled image already carried -- + // so the "prebuilt image for fast startup" above still paid for a build. + // With this block gone the launch is a pull and nothing else. // // Adding a feature back here is allowed and costs that derived build again. // If that ever becomes the normal case, the fix is devlaunch's design -- @@ -63,7 +70,9 @@ }, // Three mounts. The pixi volume keeps the environment out of the bind- - // mounted workspace; the other two share host credentials. + // mounted workspace; the other two share host credentials. docker will not + // create the container when a bind source is missing, so initializeCommand + // (.devcontainer/claude-code/init-host.sh) creates both on the host first. // // ~/.config/gh is here because it works. `gh` uses a system keyring when // one is available and falls back to hosts.yml when it is not, and on this From e57dd1baf4dd4f21c56da5d6acc3961a589cbe05 Mon Sep 17 00:00:00 2001 From: Austin Gregg-Smith Date: Sun, 25 Oct 2026 21:33:36 +0000 Subject: [PATCH 3/6] chore(dependabot): drop check-manifest, mark the docker entry template-only check-manifest is no longer a dependency. The docker entry watches .devcontainer/Dockerfile, which children on the prebuilt image do not have. --- .github/dependabot.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 322103d..11c54e0 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -13,7 +13,6 @@ updates: dev-dependencies: #try to group all development dependencies updates into a single pr patterns: - - "check-manifest" - "prek" - "pytest" - "pytest-cov" @@ -24,6 +23,9 @@ updates: #try to group all third party library updates into a single pr patterns: - "*" + # Template-only: this watches .devcontainer/Dockerfile. A child repo that + # uses the prebuilt image and has no Dockerfile should drop this entry, or + # every Dependabot run reports a missing dependency file. - package-ecosystem: "docker" directory: "/.devcontainer" schedule: From 4dd590a2814f85ce3ef5428d34a918c3c81ed5c0 Mon Sep 17 00:00:00 2001 From: Austin Gregg-Smith Date: Sun, 25 Oct 2026 21:33:36 +0000 Subject: [PATCH 4/6] fix(vscode): run the pytest duration task through pixi pytest is only on PATH inside the pixi env, so the bare call failed in the devcontainer. --- .vscode/tasks.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index b83b945..ef97eec 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -52,7 +52,7 @@ "label": "pytest duration", "detail": "Run pytest and track the duration of each test", "type": "shell", - "command": "pytest --durations=0" + "command": "pixi run pytest --durations=0" }, { "label": "check CI", From ffd773a8b9ae4c0129a5d9fb9b16bfdae3de1414 Mon Sep 17 00:00:00 2001 From: Austin Gregg-Smith Date: Sun, 25 Oct 2026 21:36:35 +0000 Subject: [PATCH 5/6] fix: bind-mount drift guard missed a mount written type=bind,source=... The regex needed source= before type=bind, so a new ~/ bind mount written in the other order passed the test while init-host.sh never created it. Parse each mount string into its key=value fields instead. --- test/test_devcontainer.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/test_devcontainer.py b/test/test_devcontainer.py index bf849f7..dff6fce 100644 --- a/test/test_devcontainer.py +++ b/test/test_devcontainer.py @@ -8,7 +8,14 @@ def host_bind_sources() -> list[str]: config = (DEVCONTAINER / "devcontainer.json").read_text(encoding="utf-8") - return re.findall(r"source=\$\{localEnv:HOME\}/([^,]+),[^\"]*type=bind", config) + live = "\n".join(line for line in config.splitlines() if not line.lstrip().startswith("//")) + sources = [] + for mount in re.findall(r'"([^"]*\btype=bind\b[^"]*)"', live): + fields = dict(field.split("=", 1) for field in mount.split(",") if "=" in field) + home, _, rest = fields.get("source", "").partition("${localEnv:HOME}/") + if not home and rest: + sources.append(rest) + return sources def test_init_host_creates_every_home_bind_source(tmp_path): From f3fedaa6043eee4735c4bca11e275d952481d5e9 Mon Sep 17 00:00:00 2001 From: Austin Gregg-Smith Date: Sun, 25 Oct 2026 21:36:41 +0000 Subject: [PATCH 6/6] docs: a child repo also needs init-host.sh, not only devcontainer.json and post-create.sh The template-only comment described a child that kept two files; with initializeCommand pointing at claude-code/init-host.sh, that child cannot create its container. --- .devcontainer/devcontainer.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 78f8143..ba473fe 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -6,9 +6,10 @@ // tasks that toggle this block -- `pixi run dev-use-local` (uncomment the // "build" block below and build from the Dockerfile) and // `pixi run dev-use-prebuilt` (point "image" at this repo's own image). - // A child repo that kept only devcontainer.json and post-create.sh has - // none of those; there the commented "build" block is inert, and to build - // locally you bring them over from blooop/python_template first. + // A child repo that kept only devcontainer.json, post-create.sh and + // claude-code/init-host.sh (the initializeCommand below) has none of + // those; there the commented "build" block is inert, and to build locally + // you bring them over from blooop/python_template first. // "build": { // "dockerfile": "Dockerfile", // "context": ".."