GitNexus/.github/workflows/ci-devcontainer.yml
Gergő Magyar 5b968a098c
fix(devcontainer): move workspace and snapshots to Linux volumes (#3835)
* fix(devcontainer): move workspace and snapshots to Linux volumes

* fix(devcontainer): exclude evaluation virtualenv from source import

* fix(devcontainer): preserve WSL links during volume imports

* fix(devcontainer): skip parser caches and report import progress

Exclude regenerable GitNexus parser caches from every nested worktree
while preserving graph databases, Git state, and local work.

Report archive bytes and elapsed time every five seconds, and stream
output with activity updates during longer Docker initialization stages.

* fix(devcontainer): resolve workspace volume ID before startup

* fix(devcontainer): relink nested worktrees and harden host imports

- Relink nested worktrees whose Git pointers still name the host path
  (C:/..., /Users/...): match the longest existing suffix in the copy
  and rewrite both pointers, as `git worktree repair` would.
- Fail the import when a file changes while tar reads it. bsdtar on
  macOS and Windows pads or truncates such files and exits 0.
- Disable AppleDouble `._*` entries from macOS tar (COPYFILE_DISABLE).
- Follow selected snapshot roots that are symlinks (dotfile-managed
  ~/.config/gh, ~/.claude.json) like the bind mounts they replace.
- Keep node at UID 1000 for root host users; the Dev Containers CLI
  skips UID realignment for UID 0.
- Make fixture modes independent of the process umask and check the
  no-partial-write case with lstat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(devcontainer): stage on the host and commit once at container creation

initializeCommand also runs when an existing container is reopened. A
developer who pulled the volume change and reopened the old bind-mount
container got an import marked ready, and the eventual rebuild silently
showed that stale copy.

- The host now only stages the checkout into gitnexus-seed-<id>
  (tree/ plus a stage-complete marker written last); the helper mounts
  the source volume read-only.
- onCreateCommand, which runs once per container creation, commits a
  complete stage into the empty source volume, empties the stage and
  repairs ownership. initializeCommand copies the host's
  seed-workspace.cjs into the seed volume on every start, so the
  commit matches devcontainer.json and works with any image.
- Staging and snapshot retakes are best-effort: a failure clears its
  target, warns and is retried next start, so a busy host never locks
  out reopening an existing container. Creation without a complete
  stage stops at onCreateCommand with a clear message.
- Snapshots are retaken while the source volume is uncommitted, and a
  partial snapshot is replaced instead of failing closed; snapshots are
  read-only host copies, so replacing them is safe.
- Node writes the tar stream (ustar + PAX for long and UTF-8 names).
  Windows tar.exe read the file list in the ANSI code page, so any
  non-ASCII path failed; macOS tar added AppleDouble files; both padded
  or truncated a file that changed while being read. A changed file now
  discards that copy. The host no longer needs tar. Sockets and FIFOs
  are skipped, as tar did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(devcontainer): simplify importer helpers and read small files whole

- tarStream reads files up to 1 MiB in one call instead of opening a
  stream per file: 50k files stream in 1.0 s instead of 12 s, with a
  byte-identical archive and unchanged change detection.
- Drop copyArchive's dead `excludes` parameter; the snapshot marker is
  excluded through the existing predicate.
- Share the source/target overlap check and the common-dir check.
- Remove exports with no consumer and two comments left from the
  host-tar implementation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(devcontainer): skip POSIX-only tar assertions on Windows (#3835)

- Address PR review feedback: the tar round-trip test ran mkfifo and
  asserted a 0755 mode unconditionally. Split it: UTF-8, long-name and
  empty-file round-trips run everywhere; POSIX mode preservation and
  FIFO exclusion move to a test skipped on win32, where tarStream
  writes 0644 by design.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(devcontainer): skip POSIX-tooling importer tests on Windows (#3835)

- Address PR review feedback: the Docker-adapter fixture assumed a POSIX
  PATH separator. A Windows-safe separator would not help: the fake
  `docker` is a shebang script Windows cannot spawn, and it runs Linux
  helper commands. One shared `posixOnly` skip option now covers the
  seven Docker-adapter tests, the bash credential test and the POSIX
  modes/FIFO test; all still run on Linux.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(devcontainer): keep failed snapshots retryable and nested worktrees local (#3835)

Address PR review feedback:
- Select snapshot roots with lstat, so a dangling or unfollowable
  `.claude.json` link reaches the archiver and is preserved as a link.
  A path under a non-directory still counts as absent.
- post-create.sh publishes the one-shot identity and shareable seed
  markers only when /host carries its completion marker; a snapshot
  skipped during initialization is seeded by a later rebuild.
- Remove an absolute core.worktree from each relinked nested worktree's
  config.worktree before Git first reads that checkout, as already done
  for the root configuration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(devcontainer): run fake-Docker importer tests only on Linux (#3835)

- Address PR review feedback: on macOS the importer passes container
  UID 1000, and the fake Docker adapter ran finishSnapshot's chown as the
  unprivileged host user. The adapter emulates the Linux helper
  container on the host, so its seven tests now share a `linuxHelper`
  gate; the bash, mode and FIFO tests keep the narrower `posixOnly`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci(devcontainer): run host importer tests on macOS and Windows (#3835)

Address PR review feedback: the suite's platform assumptions surfaced one
review finding per push. The host-side importer now runs on all three CI
hosts and the tests state what each one needs.

- New `host-importer` job runs initialize-volumes.test.cjs on
  macos-latest and windows-latest (Linux already runs every test).
- The importer reads its Docker CLI from GITNEXUS_IMPORT_DOCKER (JSON
  argv, default docker). Windows spawn resolves only .exe/.com, so the
  test adapter is now a Node script on every OS instead of a shebang
  file on PATH. The adapter emulates the helper's find/mkdir/touch and,
  on Windows, snapshot finalization.
- Gates: posixOnly (bash, modes, mkfifo), a symlink capability probe,
  and containerSide (Linux only) for code that runs only in the dev
  container or helper. Host staging assertions read the staged tree;
  the commit and 0600 snapshot modes stay in one Linux test.
- seed-workspace.test.cjs is container-side, so it skips on other hosts.
- The long-name round trip stays above 100 bytes (PAX) but under
  Windows MAX_PATH once extracted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(devcontainer): verify the tar stream with Python's PAX reader (#3835)

Windows tar.exe converts names to the ANSI code page while extracting, so
it cannot write `jegyzet-ő.md` or an emoji directory ("empty or
unreadable filename") - the limitation the Node writer exists to avoid.
Production never extracts with it; Docker's Go extractor does.

Read the round-trip archive with Python's tarfile instead, an
independent PAX reader that handles UTF-8 on every host, so the UTF-8
check also runs on Windows CI. A capability gate skips the test when no
Python 3 is installed. Removing the PAX path record fails the test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 20:36:27 +00:00

161 lines
6.9 KiB
YAML

name: Devcontainer Smoke
# Smoke-tests .devcontainer/ whenever it changes. Two things happen here.
# First, unit tests cover host->container config transforms and actual Husky
# pre-commit enforcement in temporary repositories. Second, the image is built
# through the standard @devcontainers/cli path. That CLI reads build.args from
# devcontainer.json, so the version pin there stays the single source of truth.
on:
push:
branches: [main]
paths:
- '.devcontainer/**'
- '.github/workflows/ci-devcontainer.yml'
- 'gitnexus-web/package-lock.json'
pull_request:
paths:
- '.devcontainer/**'
- '.github/workflows/ci-devcontainer.yml'
- 'gitnexus-web/package-lock.json'
permissions:
contents: read
# Concurrency convention: see CONTRIBUTING.md → "GitHub Actions — Concurrency Convention".
# Grouped per branch or tag. Cancel a PR run when a newer one replaces it.
# Never cancel a push-to-main run.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
config-transforms:
name: Config-transform unit tests
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
# persist-credentials: false — this job only reads (tests and syntax
# checks) and never pushes. The setting keeps GITHUB_TOKEN out of
# .git/config, which zizmor flags as the "artipacked" issue.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
# Hook tests install real Husky in temporary repositories.
- name: Install hook test tooling
run: |
npm ci --no-audit --no-fund
node .devcontainer/verify-git-hooks.cjs
- name: Unit-test devcontainer setup and hooks
run: node --test .devcontainer/*.test.cjs
- name: Syntax-check the lifecycle shell scripts
run: |
bash -n .devcontainer/install-deps.sh
bash -n .devcontainer/post-create.sh
bash -n .devcontainer/seed-codex.sh
bash -n .devcontainer/tune-9p.sh
# initialize-volumes.cjs runs on developer hosts before the container exists,
# so its tests also run on macOS and Windows. Container-side tests skip there.
# The importer needs only Node, Git and the host's tar; no npm install.
host-importer:
name: Host importer tests (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest]
steps:
# persist-credentials: false — read-only test job; see config-transforms.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
- name: Unit-test the host-side importer
run: node --test .devcontainer/initialize-volumes.test.cjs
build:
name: Build devcontainer image (${{ matrix.profile }})
runs-on: ubuntu-latest
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
profile: [default, ui]
steps:
# persist-credentials: false — this is a read-only build smoke that
# never pushes. The setting keeps GITHUB_TOKEN out of .git/config,
# which zizmor flags as the "artipacked" issue.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
- name: Generate UI profile
if: matrix.profile == 'ui'
run: node .devcontainer/profile.cjs ui
# Builds the image the same way a developer's "Reopen in Container" does.
# @devcontainers/cli reads devcontainer.json (jsonc format), resolves
# build.args (including BUN_VERSION), and runs the Dockerfile. This smoke
# catches Dockerfile regressions, including native CLI installation.
# The lifecycle hooks (post-create.sh) do not
# run here. They need the host config mounts, and CI has none.
#
# ARCH COVERAGE: this runs on an x64 runner with no --platform or QEMU, so
# it builds only amd64. Native CLI installers also support arm64, but that
# path is not built here. Add QEMU and a linux/arm64 matrix leg if needed.
#
# The @devcontainers/cli version is pinned on purpose. A bare
# `npx --yes @devcontainers/cli` would resolve @latest at run time. A
# breaking or malicious publish could then change CI behavior, or change
# how devcontainer.json is read, with no diff to show for it. Bump this pin
# deliberately, alongside the Dockerfile and devcontainer.json pins.
#
# @devcontainers/cli wraps the Dockerfile with `# syntax=docker/dockerfile:1`,
# which BuildKit resolves from Docker Hub. Hub blips surface as
# `DeadlineExceeded` / `i/o timeout` on the syntax frontend (see run
# 26797815133). Build retry (2 attempts, 45s backoff) matches
# `.github/actions/docker-build-push-retry` (docker/build-push-action#1422).
# Pre-pull of docker/dockerfile:1 is extra hardening; best-effort so the
# build retry still runs if Hub is flaky only during pull.
- name: Pre-pull BuildKit Dockerfile frontend (retry)
continue-on-error: true
run: |
set -euo pipefail
img="docker/dockerfile:1"
for attempt in 1 2 3; do
if docker pull "$img"; then
exit 0
fi
echo "::warning::docker pull ${img} attempt ${attempt} failed"
if [ "$attempt" -lt 3 ]; then
sleep $((attempt * 15))
fi
done
echo "::warning::failed to pre-pull ${img} after 3 attempts; continuing — build step may still succeed"
exit 1
- name: Build devcontainer via @devcontainers/cli
env:
DEVCONTAINER_CONFIG: ${{ matrix.profile == 'ui' && '.devcontainer/generated/devcontainer.json' || '.devcontainer/devcontainer.json' }}
run: |
set -euo pipefail
for attempt in 1 2; do
if npx --yes @devcontainers/cli@0.87.0 build --workspace-folder . --config "$DEVCONTAINER_CONFIG" --frozen-lockfile; then
if [ "$attempt" -eq 2 ]; then
echo "::notice::devcontainer build retry succeeded (attempt 2); investigate if this recurs across runs."
fi
exit 0
fi
if [ "$attempt" -eq 2 ]; then
echo "::error::devcontainer build failed after 2 attempts"
exit 1
fi
echo "::warning::devcontainer build attempt ${attempt} failed; retrying in 45s…"
sleep 45
done