Skip to content

[Task] Harden workspace tooling: fresh-clone uv sync, Spark interpreter, guard docs and app port validation #101

Closed

Description

@DavidVFitzGerald

Delivery phase

Workflow / roadmap / environment bootstrap. This is container-tooling and developer-documentation hardening of the existing workspace and ./dev wrapper. It changes no application behavior.

Goal

A fresh clone can run the documented workspace backend targets without hidden steps. The ETL Spark tests honor an overridden virtual-environment location. The test-guard documentation matches the code. A bad LCA_APP_*_PORT value produces a clear, range-checked error that affects only the app-* commands.

Source: non-blocking L1 QA notes 1, 3 and 6 on #96 (QA PASS at 59dce85, merged in PR #100 at 41c6b14).

Context and authority

Read AGENTS.md (containers and required technology), docs/adr/0003-rootless-development-workspace.md, docs/engineering/development-environment.md, README.md ("Open the development workspace" and "Run the local application"), specification §3.1 and §3.3 (frozen uv workspace, documented container commands). Do not read the archive or reference folders.

Repository facts at 41c6b14:

  1. Fresh-clone sync. ./dev up does not run .devcontainer/check-env.sh, which is the Dev Containers postCreateCommand and runs uv sync --frozen without --all-packages. So a fresh ./dev shell has no synced workspace environment. The make backend-* targets in Makefile run uv run --frozen ... and need uv sync --frozen --all-packages first. CI does this explicitly (.github/workflows/backend.yml), but the developer docs do not.
  2. Spark interpreter pin. data_pipeline/Dockerfile sets PYSPARK_PYTHON=/workspaces/lca-diff/.venv/bin/python. If UV_PROJECT_ENVIRONMENT is overridden in the ETL container (for example /var/tmp/lca-venv, which L1 used on a tmpfs worktree), Spark workers use a missing or different interpreter, and the Spark tests fail.
  3. Test-guard wording. development-environment.md ("Isolation", local application stack section) says the destructive suites refuse any host other than postgres/postgres-target. In fact apps/api/tests/conftest.py and packages/python/lca_shared/tests/test_schema.py also accept localhost and 127.0.0.1. data_pipeline/tests/test_publication.py (postgres/postgres-target) and test_seed.py (postgres-target only) are stricter.
  4. Port validation. dev lines 25–28 validate LCA_APP_FRONTEND_PORT, LCA_APP_API_PORT and LCA_APP_AUTH_PORT at top level for every command, using a digits-only regex with no range check. So an invalid value blocks unrelated commands such as ./dev shell and ./dev up, while 0 or 70000 pass validation.

Requirements and constraints

  • Fresh-clone sync (fact 1). Make the required step explicit and reliable. Either document uv sync --frozen --all-packages as the first step in the workspace section of the README and development-environment.md, or have the container-side entry point perform it (for example a make backend-sync target, or the backend-* targets syncing with --all-packages). Keep frozen installs and the single uv.lock. Do not change the lock.
  • Spark interpreter (fact 2). Spark workers must use the interpreter of the active uv environment, so that overriding UV_PROJECT_ENVIRONMENT keeps make backend-test-etl and make backend-test-seed working. One option is to derive PYSPARK_PYTHON from the active environment (for example sys.executable in the Spark session or test setup) rather than the image's fixed path. Another is to document and enforce that both variables are overridden together. Keep the default image behavior unchanged.
  • Guard wording (fact 3). Correct the documentation to state each suite's actual host allowlist. Changing the guards themselves is out of scope unless a guard is found to be unsafe; if so, report it and do not widen it.
  • Port validation (fact 4). Validate the LCA_APP_*_PORT values only for app-* commands (and make up/make down), and accept only integers 1–65535. Produce one clear error that names the variable. Non-app commands must be unaffected by an invalid app port.
  • Host changes are limited to the dev wrapper and documentation. All tooling runs in containers. Install nothing on the host. Preserve the rootless preflight.
  • Coordination. L2 [Task] L2 — Connect the frontend to the real API and Auth Emulator #97 also edits dev (an LCA_APP_PROJECT collision guard) and the README. Implement this issue after [Task] L2 — Connect the frontend to the real API and Auth Emulator #97 merges, or rebase onto it. Do not reimplement [Task] L2 — Connect the frontend to the real API and Auth Emulator #97's guard.

Acceptance criteria

  • AC1. From a fresh clone (no .venv, no .env), following only the documented steps, ./dev up, ./dev shell, then make backend-format-check backend-lint backend-typecheck backend-test-unit all exit 0. The exact commands and results are recorded.
  • AC2. In the ETL container with UV_PROJECT_ENVIRONMENT=/var/tmp/lca-venv (after a frozen --all-packages sync into it), ./dev etl-run make backend-test-etl (or the documented equivalent) and ./dev publication-run make backend-test-seed pass. With the default environment they still pass.
  • AC3. development-environment.md states the actual host allowlist of each guarded suite (API/schema: postgres, localhost, 127.0.0.1; publication: postgres, postgres-target; seed: postgres-target). This matches the code at the delivered SHA.
  • AC4. LCA_APP_API_PORT=abc ./dev shell and LCA_APP_API_PORT=70000 ./dev up are not blocked by the app port (each behaves as without the variable). LCA_APP_API_PORT=abc ./dev app-up, LCA_APP_API_PORT=0 ./dev app-up and LCA_APP_API_PORT=65536 ./dev app-status exit nonzero before any container starts, with a message naming the variable. A valid LCA_APP_API_PORT=8011 ./dev app-up still works.
  • AC5. No change to uv.lock, the application code or the API/ETL runtime images beyond what fact 2 requires. Hosted CI stays green.

Out of scope and follow-ups

Verification plan

On the host: git clone into a scratch directory, and use a distinct COMPOSE_PROJECT_NAME and ports. Run ./dev up, ./dev shell, and the AC4 ./dev invocations, recording the exit codes.

Inside containers:

  • the backend make targets in AC1;
  • ./dev etl-run / ./dev publication-run with and without UV_PROJECT_ENVIRONMENT for AC2 (the ETL overlay needs an existing LCA_PRIVATE_INPUT_DIR; an empty directory works).

AC3 is verified by inspection against the guard code. No new commands are required unless the engineer adds a sync target; if one is added, document its exact invocation.

Dependencies and readiness

Activity

  1. added
    task
    on Nov 16, 2026
  2. DavidVFitzGerald commented on Nov 16, 2026

    @DavidVFitzGerald
    OwnerAuthor

    PM: READY

    Issue #101 is ready against merged origin/main at cd6d8a6557b65d40a5d3d12b5278f0eec9aefee0 (L2 PR #105). The maintainer explicitly requested this tooling follow-up after L2 on 2026-11-16. Existing acceptance criteria and scope remain unchanged.

    Phase and dependencies: workspace/container tooling hardening. L1 #96 is merged, and the scheduling dependency on L2 #97 is satisfied by PR #105. One issue and one PR; no product/scientific decision or ADR is needed. Specification §§3.1/3.3, ADR 0003, and the current root instructions govern rootless execution, frozen installs and the single lock.

    Scope confirmed against current code:

    • Document or provide the reliable frozen uv sync --frozen --all-packages step before the existing backend targets; do not change uv.lock.
    • Make Spark workers use the active uv interpreter, preserving default behavior and supporting UV_PROJECT_ENVIRONMENT=/var/tmp/lca-venv.
    • Document actual destructive-test host allowlists: API/schema postgres, localhost, 127.0.0.1; publication postgres, postgres-target; seed postgres-target. The guards also require database lca. Do not widen guards.
    • Scope validation of all three LCA_APP_*_PORT settings to app-* commands, accept integers 1–65535, and name the failing variable before any Compose call. Preserve L2's project-collision guard and rootless preflight.
    • No application semantics, unrelated runtime-image changes or new CI jobs. Seed-report labels remain [Task] L1 follow-ups: label synthetic seed reports and verify an uncached app-stack image rebuild #103.

    Engineering and QA plan: start an isolated worktree/branch from merged main, with distinct workspace/app project names and ports. Use an existing empty private-input directory for the ETL mount. From a fresh clone with no .env or .venv, follow only the documented workspace steps and run AC1's four backend checks. Run actual ETL and seed suites both with the default environment and with /var/tmp/lca-venv, frozen-synced inside their containers. Verify port negatives and non-app invocations, a live valid-port app start, unchanged guards/lock, and existing hosted checks at the delivered SHA. Record exact commands, outcomes and unavailable evidence; QA independently verifies the delivered commit.

    Implementation pitfalls: avoid integer overflow or shell octal interpretation for long/leading-zero port inputs; keep all port validation out of non-app commands; pass the override into the container process rather than assuming a host environment variable crosses Compose exec; keep disposable test databases isolated from the app stack.

    Next: Software Engineer implements #101, then independent QA. No source or criteria changes were made during this PM assessment.

  3. DavidVFitzGerald commented on Nov 16, 2026

    @DavidVFitzGerald
    OwnerAuthor

    Coordinator: IMPLEMENTING after PM READY. Branch fix/101-workspace-tooling in isolated worktree .task-worktrees/tooling-101, based on merged main cd6d8a6 (PR #105). Rootless preflight/toolchain checks pass. Scope is the four documented tooling defects; verification includes fresh-clone backend checks, real ETL/seed suites with default and overridden environments, and app-only port validation. Independent QA will review the delivered commit. #97 is closed after its authorized merge.

  4. DavidVFitzGerald commented on Nov 16, 2026

    @DavidVFitzGerald
    OwnerAuthor

    Engineering: READY FOR QA

    Branch fix/101-workspace-tooling; candidate e1077a418a4294ac6a32cb28439f93395ec1c46a; draft PR #106: #106.

    All five criteria are implemented and local engineering checks pass. Hosted Backend/Frontend/ETL workflows are queued/running at this SHA; they are not yet claimed green. Independent QA remains required.

    • AC1: A real fresh local clone began with no .env or .venv. Documented ./dev up → interactive ./dev shell → uv sync --frozen --all-packages → make backend-format-check backend-lint backend-typecheck backend-test-unit all exited 0: 15 unit tests, MyPy 47 source files. The final regression source also passes those four checks in the implementation container.
    • AC2: Actual frozen ETL/publication runs passed in default .venv and UV_PROJECT_ENVIRONMENT=/var/tmp/lca-venv: 1 real Spark/PostgreSQL ETL test + 6 seed tests each. The golden test retains a nonexistent inherited worker path. Real workers reported their active interpreter in both environments; running the pre-fix extraction source failed with the same inherited stale path.
    • AC3: Documentation now matches the unchanged API/schema (postgres, localhost, 127.0.0.1), publication (postgres, postgres-target) and seed (postgres-target) allowlists, all requiring database lca.
    • AC4: Existing guard regression script passes all three ports/every app command, range endpoints, long leading zeros/oversized numbers, literal quoted/commented dotenv values, environment precedence and non-app isolation. Real abc shell and 70000 workspace startup exit 0; abc/0 app-up and 65536 app-status exit 2 with variable/range, without changing app container IDs. A dedicated app on API port 8011 starts and passes app-smoke. Workspace config and explicit app app-config remain daemon-free. Literal-only dotenv ports are documented; expressions require an explicit process environment value.
    • AC5: Lock, API code, Compose definitions, runtime Dockerfiles and workflow files are unchanged; no new CI jobs. Hosted results pending.

    Reproduction and exact commands: docs/engineering/tooling-101-verification.md. No ADR deviation. Historical folders excluded; no host dependencies installed or licensed inputs used.

    Isolation: implementation worktree /home/david/projects/LCA-diff/.task-worktrees/tooling-101, workspace/publication project lca-diff-101-eng port 5271; fresh clone .../tooling-101-fresh, project lca-diff-101-fresh port 5273. The own app lca-diff-101-eng-app (5272/8011/9272) was stopped via guarded app-down, retaining volumes and freeing API 8011 for independent QA. Existing L2 app and main workspace were left untouched. Logs: host /tmp/lca-101-*, plus fresh-clone container /tmp/lca-101-fresh-backend.log.

    Next: independent QA at the candidate SHA, hosted checks, then maintainer review. Issue remains open; no merge performed.

  5. DavidVFitzGerald commented on Nov 16, 2026

    @DavidVFitzGerald
    OwnerAuthor

    QA: PASS

    Reviewed commit: e1077a418a4294ac6a32cb28439f93395ec1c46a, branch fix/101-workspace-tooling, PR #106, based on merged L2 at cd6d8a6.

    Independent clean clone: /home/david/projects/LCA-diff/.task-worktrees/qa-tooling-101-e1077a4. Before setup it had neither .env nor .venv. QA changed no source, tests or criteria; the checkout remains clean. All tools, installs and tests ran in rootless containers, with namespace user 0:0, all capabilities dropped and no-new-privileges. Docker 29.9.3 reports rootless; Python 3.14.2/uv 0.9.30 and the committed frozen lock were used.

    Criterion Verdict and independent evidence
    AC1 — fresh-clone backend setup PASS. Followed documented ./dev config, ./dev up, actual interactive ./dev shell, then uv sync --frozen --all-packages and all four requested backend targets. Every command exited 0. Formatter: 62 files already formatted; lint passes; MyPy: no issues in 47 source files; unit suite: 15 passed, 18 deselected. No database/private input was started or supplied for these checks.
    AC2 — default/overridden Spark environment PASS. Actual golden Spark/PostgreSQL ETL and seed suites passed in both environments against QA-only postgres/postgres-target. Default: 1 ETL test passed (18.47 s), 6 seed tests passed (11.50 s). Frozen-synced /var/tmp/lca-venv: 1 ETL test passed (18.78 s), 6 seed tests passed (11.36 s). The override was passed inside the container, and its driver reports /var/tmp/lca-venv/bin/python3. The retained golden test deliberately sets an inherited nonexistent worker path, so actual Spark workers exercise the fix. Reviewed the sole Spark builder: it sets PYSPARK_PYTHON=sys.executable before session creation.
    AC3 — guard documentation PASS. Compared docs with the delivered guard code: API/schema allow postgres, localhost, 127.0.0.1; publication allows postgres, postgres-target; seed allows only postgres-target. All require database lca. Guard implementations are unchanged; no allowlist was widened.
    AC4 — app-only port validation PASS. Actual LCA_APP_API_PORT=abc ./dev shell opens/exits 0; LCA_APP_API_PORT=70000 ./dev up exits 0. Required app negatives (abc/0 with app-up, 65536 with app-status) exit 2, naming the variable and range; no QA app containers existed before/after them. A separate actual app-up with API 8011 succeeds and its real auth/precision/CORS smoke passes 9/9. Expanded container regression matrix passes for all three ports/every app command, range endpoints, empty/oversized values, leading zeros, quoted/commented dotenv values (including no-space quoted comments), invalid dotenv settings, environment precedence and existing L2 collision cases. config with invalid app port and app-config with valid ports both exit 0 against a nonexistent Docker socket, proving the documented daemon-free split.
    AC5 — scope and CI PASS. uv.lock, API code, runtime Dockerfiles, Compose files and workflow files are byte-unchanged from cd6d8a6; no new CI job was added. Changes are limited to the wrapper, Spark interpreter fix/regression, existing guard regression script and current documentation. No product/scientific/API semantics changed and no ADR is required. uv lock --check passes; all five hosted jobs pass at the reviewed SHA, and PR #106 reports CLEAN.

    Exact setup/check commands:

    # Host, in the fresh clone:
    export COMPOSE_PROJECT_NAME=lca-diff-101-qa FRONTEND_PORT=5281
    ./dev config
    ./dev up
    ./dev shell
    # Actual interactive container shell:
    uv sync --frozen --all-packages
    make backend-format-check backend-lint backend-typecheck backend-test-unit
    # In the same workspace container:
    uv run --frozen python ops/local/test_project_guard.py
    uv lock --check

    The documented empty private/empty-input directory was then created inside the workspace container. ETL/publication checks used a separate Compose project:

    # Host:
    export COMPOSE_PROJECT_NAME=lca-diff-101-qa-etl FRONTEND_PORT=5282
    export LCA_PRIVATE_INPUT_DIR="$PWD/private/empty-input"
    ./dev publication-up
    ./dev publication-run bash -c 'uv sync --frozen --all-packages && env LCA_DATABASE_URL=postgresql+psycopg://lca_migrator:local-migration-only@postgres/lca uv run --frozen alembic upgrade head && make backend-test-etl backend-test-seed'
    ./dev publication-run env UV_PROJECT_ENVIRONMENT=/var/tmp/lca-venv bash -c 'uv sync --frozen --all-packages && uv run --frozen python -c "import sys; print(sys.executable)" && make backend-test-etl backend-test-seed'

    Live app verification used LCA_APP_PROJECT=lca-diff-101-qa-app, frontend 5280, API 8011 and auth 9280, with ./dev app-up then ./dev app-smoke. Daemon-free probes set DOCKER_HOST=unix:///tmp/lca-101-qa-no-daemon.sock. All destructive database tests were restricted to the QA publication project's disposable databases. No application reset or named-volume deletion was performed; the primary workspace and existing L2 application were untouched.

    Independent logs: /tmp/lca-101-qa-fresh-backend.log, /tmp/lca-101-qa-guards.log, /tmp/lca-101-qa-default-etl-seed.log, /tmp/lca-101-qa-override-etl-seed.log, /tmp/lca-101-qa-app-up.log and /tmp/lca-101-qa-app-smoke.log. The fresh-backend log is also retained inside its workspace container.

    Hosted evidence: Backend/API, ETL, Frontend/real-stack.

    No blocking defects or missing required evidence remain. Next owner: coordinator/maintainer for PR #106 review and explicit merge. QA leaves the issue open and does not merge or close it.

  6. DavidVFitzGerald commented on Nov 16, 2026

    @DavidVFitzGerald
    OwnerAuthor

    Coordinator: READY FOR REVIEW

    Issue #97 is closed following the maintainer's merge of PR #105 at cd6d8a6. Task #101 is implemented in PR #106 on fix/101-workspace-tooling, candidate e1077a418a4294ac6a32cb28439f93395ec1c46a, based on that merged main.

    Independent QA PASS verifies AC1–AC5. A clean disk-backed clone with no .env or .venv follows the documented interactive workspace/frozen all-packages setup and passes all four backend targets (15 unit tests; MyPy 47 sources). The actual Spark/PostgreSQL ETL test and all six seed tests pass in both default and /var/tmp/lca-venv environments. The retained Spark regression starts with a nonexistent inherited worker path. Guard/port regressions, live invalid/non-app commands, daemon-free configuration and the isolated API-8011 app startup/smoke pass. All five hosted jobs pass at the delivered SHA.

    The change documents frozen setup and exact test guard allowlists, selects the active worker interpreter, and validates app ports only for app-*. config is workspace-only; app-config explicitly validates the app. Literal dotenv port values retain environment precedence; interpolation requires an explicit evaluated process-environment value as documented. The dependency lock, API, runtime image recipes, Compose definitions, existing test guards and workflow definitions are unchanged; no new CI jobs or ADR.

    Exact commands and engineering evidence: docs/engineering/tooling-101-verification.md. Independent QA evidence is recorded on this issue. The implementation worktree is clean at .task-worktrees/tooling-101; no host installs, private-data imports, volume resets, merge or issue closure were performed for #101.

    Next action: maintainer review/merge of PR #106; leave #101 open until approved merge. L3 #30 remains the next required local-MVP milestone, and #103 remains a separate optional hardening follow-up.

  7. DavidVFitzGerald commented on Nov 16, 2026

    @DavidVFitzGerald
    OwnerAuthor

    Coordinator: closing after the maintainer merged PR #106 at baff738. Independent QA PASS: #101 (comment) . All five delivered-head CI jobs passed. Per the maintainer instruction, no L3 work is started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    task

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions