From cde40419f3c4b146bad41dcaae049214a51b706c Mon Sep 17 00:00:00 2001 From: Christopher MANEU Date: Tue, 3 Nov 2026 14:28:28 +0000 Subject: [PATCH 1/8] WIP - Kind --- .devcontainer/Dockerfile | 48 + .devcontainer/devcontainer-lock.json | 9 + .devcontainer/devcontainer.json | 40 + .devcontainer/install-tools.sh | 65 + .devcontainer/kind/base/kustomization.yaml | 4 + .devcontainer/kind/base/resources.json | 3522 +++++++++++++++++ .devcontainer/kind/cluster.yaml | 12 + .../components/kubedock/kustomization.yaml | 64 + .../kind/components/kubedock/rbac.yaml | 47 + .../kind/overlays/debug/kustomization.yaml | 12 + .../kind/overlays/fast/kustomization.yaml | 12 + .devcontainer/native.compose.yaml | 79 + .devcontainer/runtime.Dockerfile | 15 + .devcontainer/skaffold.yaml | 38 + .devcontainer/spike/compose.yaml | 46 + .dockerignore | 1 + .github/workflows/devcontainer.yml | 55 + .gitignore | 3 + .vscode/launch.json | 68 + AGENTS.md | 1 + CONTRIBUTING.md | 12 + ENV_VARIABLES.md | 19 +- apps/model-scanners/anthropic/Dockerfile | 3 + apps/model-scanners/copilot/Dockerfile | 3 + apps/portal/vite.config.ts | 7 + docs/architecture/auth-rbac.md | 7 + docs/architecture/devcontainer.md | 204 + docs/architecture/kubedock.md | 6 + package.json | 13 + scripts/dev/acceptance.ts | 53 + scripts/dev/bootstrap.ts | 91 + scripts/dev/cluster.ts | 143 + scripts/dev/config.test.ts | 79 + scripts/dev/config.ts | 165 + scripts/dev/control.ts | 329 ++ scripts/dev/inventory.ts | 42 + scripts/dev/kind.test.ts | 42 + scripts/dev/kind.ts | 108 + scripts/dev/runtime.test.ts | 128 + scripts/dev/spike.test.ts | 62 + scripts/dev/spike.ts | 201 + scripts/dev/workers.ts | 52 + .../content/docs/resources/contributing.md | 8 + 43 files changed, 5913 insertions(+), 5 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer-lock.json create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/install-tools.sh create mode 100644 .devcontainer/kind/base/kustomization.yaml create mode 100644 .devcontainer/kind/base/resources.json create mode 100644 .devcontainer/kind/cluster.yaml create mode 100644 .devcontainer/kind/components/kubedock/kustomization.yaml create mode 100644 .devcontainer/kind/components/kubedock/rbac.yaml create mode 100644 .devcontainer/kind/overlays/debug/kustomization.yaml create mode 100644 .devcontainer/kind/overlays/fast/kustomization.yaml create mode 100644 .devcontainer/native.compose.yaml create mode 100644 .devcontainer/runtime.Dockerfile create mode 100644 .devcontainer/skaffold.yaml create mode 100644 .devcontainer/spike/compose.yaml create mode 100644 .github/workflows/devcontainer.yml create mode 100644 docs/architecture/devcontainer.md create mode 100644 scripts/dev/acceptance.ts create mode 100644 scripts/dev/bootstrap.ts create mode 100644 scripts/dev/cluster.ts create mode 100644 scripts/dev/config.test.ts create mode 100644 scripts/dev/config.ts create mode 100644 scripts/dev/control.ts create mode 100644 scripts/dev/inventory.ts create mode 100644 scripts/dev/kind.test.ts create mode 100644 scripts/dev/kind.ts create mode 100644 scripts/dev/runtime.test.ts create mode 100644 scripts/dev/spike.test.ts create mode 100644 scripts/dev/spike.ts create mode 100644 scripts/dev/workers.ts diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..2ba74ad5b --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,48 @@ +FROM node:22.22.0-bookworm@sha256:20a424ecd1d2064a44e12fe287bf3dae443aab31dc5e0c0cb6c74bef9c78911c + +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates curl git sudo openssl mkcert libnss3-tools iptables jq \ + build-essential pkg-config libssl-dev cmake clang lldb libclang-dev \ + python3 python3-venv python3-pip xz-utils unzip chromium xvfb x11vnc novnc websockify \ + && rm -rf /var/lib/apt/lists/* \ + && printf 'node ALL=(root) NOPASSWD:ALL\n' > /etc/sudoers.d/node \ + && chmod 0440 /etc/sudoers.d/node + +ARG TARGETARCH +RUN set -eu; \ + case "$TARGETARCH" in amd64|arm64) ;; *) echo "Unsupported architecture: $TARGETARCH"; exit 1 ;; esac; \ + curl -fsSLo /tmp/kind "https://kind.sigs.k8s.io/dl/v0.27.0/kind-linux-${TARGETARCH}"; \ + curl -fsSLo /tmp/kind.sha256 "https://kind.sigs.k8s.io/dl/v0.27.0/kind-linux-${TARGETARCH}.sha256sum"; \ + cd /tmp; sed "s/kind-linux-${TARGETARCH}/kind/" kind.sha256 | sha256sum -c -; \ + install -m 0755 kind /usr/local/bin/kind; \ + curl -fsSLo kubectl "https://dl.k8s.io/release/v1.32.2/bin/linux/${TARGETARCH}/kubectl"; \ + curl -fsSLo kubectl.sha256 "https://dl.k8s.io/release/v1.32.2/bin/linux/${TARGETARCH}/kubectl.sha256"; \ + printf '%s kubectl\n' "$(cat kubectl.sha256)" | sha256sum -c -; \ + install -m 0755 kubectl /usr/local/bin/kubectl; \ + rm -f /tmp/kind /tmp/kind.sha256 /tmp/kubectl /tmp/kubectl.sha256 + +ARG COMPOSE_VERSION=v2.35.1 +ARG BUILDX_VERSION=v0.22.0 +RUN set -eu; \ + case "$TARGETARCH" in amd64) compose_arch=x86_64 ;; arm64) compose_arch=aarch64 ;; esac; \ + mkdir -p /usr/local/lib/docker/cli-plugins; \ + cd /tmp; \ + curl -fsSLO "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/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-linux-${compose_arch}"; \ + curl -fsSLO "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/docker/compose/releases/download/${COMPOSE_VERSION}/checksums.txt"; \ + grep "docker-compose-linux-${compose_arch}$" checksums.txt | sha256sum -c -; \ + install -m 0755 "docker-compose-linux-${compose_arch}" /usr/local/lib/docker/cli-plugins/docker-compose; \ + curl -fsSLO "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/docker/buildx/releases/download/${BUILDX_VERSION}/buildx-${BUILDX_VERSION}.linux-${TARGETARCH}"; \ + curl -fsSLo buildx-checksums.txt "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/docker/buildx/releases/download/${BUILDX_VERSION}/checksums.txt"; \ + grep "buildx-${BUILDX_VERSION}.linux-${TARGETARCH}$" buildx-checksums.txt | sha256sum -c -; \ + install -m 0755 "buildx-${BUILDX_VERSION}.linux-${TARGETARCH}" /usr/local/lib/docker/cli-plugins/docker-buildx; \ + rm -f /tmp/docker-compose-linux-* /tmp/buildx-* /tmp/checksums.txt + +COPY package.json /tmp/scope-package.json +RUN npm install -g "$(node -p 'require("/tmp/scope-package.json").packageManager')" \ + && rm /tmp/scope-package.json + +COPY .devcontainer/install-tools.sh /tmp/install-tools.sh +RUN bash /tmp/install-tools.sh "$TARGETARCH" && rm /tmp/install-tools.sh +ENV PATH="/opt/cargo/bin:${PATH}" RUSTUP_HOME=/opt/rustup + +USER node \ No newline at end of file diff --git a/.devcontainer/devcontainer-lock.json b/.devcontainer/devcontainer-lock.json new file mode 100644 index 000000000..a5e6dd7d4 --- /dev/null +++ b/.devcontainer/devcontainer-lock.json @@ -0,0 +1,9 @@ +{ + "features": { + "ghcr.io/devcontainers/features/docker-in-docker:4.1.3": { + "version": "4.1.3", + "resolved": "ghcr.io/devcontainers/features/docker-in-docker@sha256:fae40f3c8be5a7c3b0db344c1d30341bc2c91ba38d1d5b14cd2ad72e6d65d084", + "integrity": "sha256:fae40f3c8be5a7c3b0db344c1d30341bc2c91ba38d1d5b14cd2ad72e6d65d084" + } + } +} \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..fbfc22fb0 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,40 @@ +{ + "name": "Scope development (DinD + native/Kind)", + "build": { "dockerfile": "Dockerfile", "context": ".." }, + "remoteUser": "node", + "features": { + "ghcr.io/devcontainers/features/docker-in-docker:4.1.3": { + "version": "29.3.0", + "moby": false, + "dockerDashComposeVersion": "none", + "installDockerBuildx": false + } + }, + "containerEnv": { + "COMPOSE_PARALLEL_LIMIT": "2", + "SCOPE_DIND_SPIKE": "1", + "SCOPE_DEV_DATA": "/home/node/.scope-state", + "CARGO_HOME": "/home/node/.cargo", + "RUSTUP_HOME": "/opt/rustup" + }, + "mounts": [ + "source=scope-pnpm-${devcontainerId},target=/home/node/.local/share/pnpm/store,type=volume", + "source=scope-cargo-${devcontainerId},target=/home/node/.cargo,type=volume", + "source=scope-data-${devcontainerId},target=/home/node/.scope-state,type=volume" + ], + "postCreateCommand": "sudo -n chown node:node /home/node/.local/share/pnpm/store /home/node/.cargo /home/node/.scope-state && pnpm install --frozen-lockfile && pnpm exec tsx scripts/dev/control.ts create", + "postStartCommand": "pnpm exec tsx scripts/dev/control.ts start", + "postAttachCommand": "pnpm exec tsx scripts/dev/control.ts attach", + "portsAttributes": { + "8080": { "label": "dev-edge (Codespaces HTTP transport)", "protocol": "http", "requireLocalPort": true, "onAutoForward": "notify" }, + "8443": { "label": "dev-edge (local HTTPS)", "protocol": "https", "requireLocalPort": true, "onAutoForward": "ignore" }, + "18443": { "onAutoForward": "ignore" } + }, + "otherPortsAttributes": { "onAutoForward": "ignore" }, + "customizations": { + "vscode": { + "settings": { "remote.autoForwardPorts": false }, + "extensions": ["vadimcn.vscode-lldb", "rust-lang.rust-analyzer", "ms-python.python", "ms-python.debugpy"] + } + } +} \ No newline at end of file diff --git a/.devcontainer/install-tools.sh b/.devcontainer/install-tools.sh new file mode 100644 index 000000000..fb8b3d828 --- /dev/null +++ b/.devcontainer/install-tools.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +set -euo pipefail + +architecture="${1:?architecture required}" +case "$architecture" in + amd64) triple=x86_64-unknown-linux-gnu; powershell_arch=x64 ;; + arm64) triple=aarch64-unknown-linux-gnu; powershell_arch=arm64 ;; + *) echo "Unsupported architecture: $architecture" >&2; exit 1 ;; +esac +temporary=$(mktemp -d) +trap 'rm -rf "$temporary"' EXIT +cd "$temporary" + +curl -fsSLo rustup-init "https://static.rust-lang.org/rustup/archive/1.28.2/${triple}/rustup-init" +curl -fsSLo rustup-init.sha256 "https://static.rust-lang.org/rustup/archive/1.28.2/${triple}/rustup-init.sha256" +sha256sum -c rustup-init.sha256 +chmod +x rustup-init +export CARGO_HOME=/opt/cargo RUSTUP_HOME=/opt/rustup +./rustup-init -y --no-modify-path --default-toolchain 1.88.0 --profile minimal --component rustfmt,clippy +export PATH="/opt/cargo/bin:$PATH" +cargo install cargo-watch --locked --version 8.5.3 + +curl -fsSLO "https://nodejs.org/dist/v24.21.0/node-v24.21.0-linux-${powershell_arch/x64/x64}.tar.xz" +curl -fsSLO https://nodejs.org/dist/v24.21.0/SHASUMS256.txt +grep "node-v24.21.0-linux-${powershell_arch}.tar.xz$" SHASUMS256.txt | sha256sum -c - +mkdir -p /opt/node24 +tar -xJf "node-v24.21.0-linux-${powershell_arch}.tar.xz" -C /opt/node24 --strip-components=1 +ln -s /usr/local/bin/node /usr/local/bin/node22 +ln -s /opt/node24/bin/node /usr/local/bin/node24 + +curl -fsSLO "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/astral-sh/uv/releases/download/0.10.0/uv-${triple}.tar.gz" +curl -fsSLO "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/astral-sh/uv/releases/download/0.10.0/uv-${triple}.tar.gz.sha256" +sha256sum -c "uv-${triple}.tar.gz.sha256" +tar -xzf "uv-${triple}.tar.gz" +install -m 0755 "uv-${triple}/uv" "uv-${triple}/uvx" /usr/local/bin/ + +curl -fsSLO "https://get.helm.sh/helm-v3.17.2-linux-${architecture}.tar.gz" +curl -fsSLO "https://get.helm.sh/helm-v3.17.2-linux-${architecture}.tar.gz.sha256sum" +sha256sum -c "helm-v3.17.2-linux-${architecture}.tar.gz.sha256sum" +tar -xzf "helm-v3.17.2-linux-${architecture}.tar.gz" +install -m 0755 "linux-${architecture}/helm" /usr/local/bin/helm + +curl -fsSLo skaffold "https://storage.googleapis.com/skaffold/releases/v2.15.0/skaffold-linux-${architecture}" +curl -fsSLo skaffold.sha256 "https://storage.googleapis.com/skaffold/releases/v2.15.0/skaffold-linux-${architecture}.sha256" +printf '%s skaffold\n' "$(awk '{print $1}' skaffold.sha256)" | sha256sum -c - +install -m 0755 skaffold /usr/local/bin/skaffold + +curl -fsSLO "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/cli/cli/releases/download/v2.67.0/gh_2.67.0_linux_${architecture}.tar.gz" +curl -fsSLO https://github.com/cli/cli/releases/download/v2.67.0/gh_2.67.0_checksums.txt +grep "gh_2.67.0_linux_${architecture}.tar.gz$" gh_2.67.0_checksums.txt | sha256sum -c - +tar -xzf "gh_2.67.0_linux_${architecture}.tar.gz" +install -m 0755 "gh_2.67.0_linux_${architecture}/bin/gh" /usr/local/bin/gh + +curl -fsSLo powershell.tar.gz "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/PowerShell/PowerShell/releases/download/v7.4.14/powershell-7.4.14-linux-${powershell_arch}.tar.gz" +curl -fsSLo powershell-hashes.txt https://github.com/PowerShell/PowerShell/releases/download/v7.4.14/hashes.sha256 +expected=$(iconv -f UTF-16 -t UTF-8 powershell-hashes.txt | tr -d '\r' | grep -i "powershell-7.4.14-linux-${powershell_arch}.tar.gz$" | awk '{print tolower($1)}') +printf '%s powershell.tar.gz\n' "$expected" | sha256sum -c - +mkdir -p /opt/powershell +tar -xzf powershell.tar.gz -C /opt/powershell +chmod +x /opt/powershell/pwsh +ln -s /opt/powershell/pwsh /usr/local/bin/pwsh + +uv venv /opt/azure-cli +uv pip install --python /opt/azure-cli/bin/python --prerelease=allow azure-cli==2.68.0 +ln -s /opt/azure-cli/bin/az /usr/local/bin/az \ No newline at end of file diff --git a/.devcontainer/kind/base/kustomization.yaml b/.devcontainer/kind/base/kustomization.yaml new file mode 100644 index 000000000..4d335a72f --- /dev/null +++ b/.devcontainer/kind/base/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - resources.json diff --git a/.devcontainer/kind/base/resources.json b/.devcontainer/kind/base/resources.json new file mode 100644 index 000000000..2f3e9adc6 --- /dev/null +++ b/.devcontainer/kind/base/resources.json @@ -0,0 +1,3522 @@ +{ + "apiVersion": "v1", + "kind": "List", + "items": [ + { + "apiVersion": "v1", + "kind": "Namespace", + "metadata": { + "name": "scope-dev" + } + }, + { + "apiVersion": "v1", + "kind": "ConfigMap", + "metadata": { + "name": "scope-runtime", + "namespace": "scope-dev" + }, + "data": { + "PUBLIC_ORIGIN": "https://localhost:8443", + "ISSUER": "https://localhost:8443/11111111-1111-1111-1111-111111111111/v2.0", + "VITE_AUTH_AUTHORITY": "https://localhost:8443/11111111-1111-1111-1111-111111111111/v2.0", + "VITE_AUTH_KNOWN_AUTHORITIES": "localhost:8443", + "VITE_AUTH_REDIRECT_URI": "https://localhost:8443", + "VITE_AUTH_POST_LOGOUT_REDIRECT_URI": "https://localhost:8443", + "VITE_AUTH_PROTOCOL_MODE": "OIDC", + "AUTH_AUTHORITY": "https://localhost:8443/11111111-1111-1111-1111-111111111111", + "AUTH_ISSUER_TEMPLATE": "https://localhost:8443/{tenantid}/v2.0", + "AUTH_JWKS_URI": "https://entra-local:8443/11111111-1111-1111-1111-111111111111/discovery/v2.0/keys", + "AUTH_PROVIDER": "entra", + "AUTH_TENANT_ID": "11111111-1111-1111-1111-111111111111", + "AUTH_API_CLIENT_ID": "cccccccc-0000-0000-0000-000000000005", + "AUTH_PORTAL_CLIENT_ID": "cccccccc-0000-0000-0000-000000000001", + "VITE_AUTH_CLIENT_ID": "cccccccc-0000-0000-0000-000000000001", + "VITE_AUTH_SCOPES": "api://cccccccc-0000-0000-0000-000000000005/access_as_user", + "VITE_AUTH_ENABLED_LOCAL": "true", + "VITE_DEV_EDGE_ORIGIN": "https://localhost:8443", + "API_ENDPOINT": "http://api:80", + "MONGO_CONNECTION_STRING": "mongodb://mongodb:27017/?replicaSet=rs0", + "MONGO_DATABASE": "scope-dev", + "REDIS_HOST": "redis", + "REDIS_PORT": "6379", + "REDIS_PASSWORD": "", + "AZURE_STORAGE_ACCOUNT_NAME": "devstoreaccount1", + "STORAGE_CONNECTION_STRING": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://azurite:10000/devstoreaccount1;QueueEndpoint=http://azurite:10001/devstoreaccount1;TableEndpoint=http://azurite:10002/devstoreaccount1;", + "JUDGE_SERVICE_URL": "http://judge:80", + "TOKEN_MANAGER_URL": "http://token-manager:80", + "NODE_TLS_REJECT_UNAUTHORIZED": "1", + "WORKER_CONCURRENCY": "1", + "SCOPE_MT_API_URL": "http://api:80", + "PORT": "80", + "NODE_EXTRA_CA_CERTS": "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/ca/rootCA.pem", + "AZURE_KEYVAULT_URI": "https://lowkey-vault:8443", + "IDENTITY_ENDPOINT": "http://lowkey-vault:8080/metadata/identity/oauth2/token", + "IDENTITY_HEADER": "header" + } + }, + { + "apiVersion": "v1", + "kind": "ConfigMap", + "metadata": { + "name": "dev-edge", + "namespace": "scope-dev" + }, + "data": { + "default.conf": "map $http_upgrade $connection_upgrade {\n default upgrade;\n '' close;\n}\nserver {\n listen 8080 ssl;\n ssl_certificate /certs/edge.pem;\n ssl_certificate_key /certs/edge-key.pem;\n\n server_name localhost;\n client_max_body_size 100m;\n proxy_http_version 1.1;\n proxy_set_header Host localhost:8443;\n proxy_set_header X-Forwarded-Proto https;\n proxy_read_timeout 3600s;\n proxy_send_timeout 3600s;\n proxy_buffering off;\n proxy_ssl_verify on;\n proxy_ssl_trusted_certificate /ca/rootCA.pem;\n proxy_ssl_server_name on;\n location ~ ^/(?:api(?:/|$)|openapi\\.json$|api-docs(?:/|$)|health$|ready$|about$) {\n proxy_pass http://api:80;\n }\n location ~ ^/(?:11111111-1111-1111-1111-111111111111|common|organizations|consumers)/(?:v2\\.0/\\.well-known/openid-configuration$|discovery/v2\\.0/keys$|oauth2/v2\\.0(?:/|$)) {\n proxy_pass https://entra-local:8443;\n }\n location = /graph/oidc/userinfo {\n proxy_pass https://entra-local:8443;\n }\n location ~ ^/(?:admin(?:/|$)|graph(?:/|$)|(?:11111111-1111-1111-1111-111111111111|common|organizations|consumers)(?:/|$)|[^/]+/(?:v2\\.0|discovery|oauth2|openid)(?:/|$)) {\n return 404;\n }\n location / {\n proxy_set_header Upgrade $http_upgrade;\n proxy_set_header Connection $connection_upgrade;\n proxy_pass http://portal:5100;\n }\n}\n" + } + }, + { + "apiVersion": "v1", + "kind": "PersistentVolume", + "metadata": { + "name": "scope-dev-mongodb" + }, + "spec": { + "capacity": { + "storage": "20Gi" + }, + "accessModes": [ + "ReadWriteOnce" + ], + "persistentVolumeReclaimPolicy": "Retain", + "storageClassName": "", + "hostPath": { + "path": "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/scope-state/mongodb", + "type": "DirectoryOrCreate" + }, + "claimRef": { + "name": "mongodb", + "namespace": "scope-dev" + } + } + }, + { + "apiVersion": "v1", + "kind": "PersistentVolumeClaim", + "metadata": { + "name": "mongodb", + "namespace": "scope-dev" + }, + "spec": { + "storageClassName": "", + "volumeName": "scope-dev-mongodb", + "accessModes": [ + "ReadWriteOnce" + ], + "resources": { + "requests": { + "storage": "20Gi" + } + } + } + }, + { + "apiVersion": "v1", + "kind": "PersistentVolume", + "metadata": { + "name": "scope-dev-redis" + }, + "spec": { + "capacity": { + "storage": "20Gi" + }, + "accessModes": [ + "ReadWriteOnce" + ], + "persistentVolumeReclaimPolicy": "Retain", + "storageClassName": "", + "hostPath": { + "path": "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/scope-state/redis", + "type": "DirectoryOrCreate" + }, + "claimRef": { + "name": "redis", + "namespace": "scope-dev" + } + } + }, + { + "apiVersion": "v1", + "kind": "PersistentVolumeClaim", + "metadata": { + "name": "redis", + "namespace": "scope-dev" + }, + "spec": { + "storageClassName": "", + "volumeName": "scope-dev-redis", + "accessModes": [ + "ReadWriteOnce" + ], + "resources": { + "requests": { + "storage": "20Gi" + } + } + } + }, + { + "apiVersion": "v1", + "kind": "PersistentVolume", + "metadata": { + "name": "scope-dev-azurite" + }, + "spec": { + "capacity": { + "storage": "20Gi" + }, + "accessModes": [ + "ReadWriteOnce" + ], + "persistentVolumeReclaimPolicy": "Retain", + "storageClassName": "", + "hostPath": { + "path": "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/scope-state/azurite", + "type": "DirectoryOrCreate" + }, + "claimRef": { + "name": "azurite", + "namespace": "scope-dev" + } + } + }, + { + "apiVersion": "v1", + "kind": "PersistentVolumeClaim", + "metadata": { + "name": "azurite", + "namespace": "scope-dev" + }, + "spec": { + "storageClassName": "", + "volumeName": "scope-dev-azurite", + "accessModes": [ + "ReadWriteOnce" + ], + "resources": { + "requests": { + "storage": "20Gi" + } + } + } + }, + { + "apiVersion": "v1", + "kind": "PersistentVolume", + "metadata": { + "name": "scope-dev-lowkey-vault" + }, + "spec": { + "capacity": { + "storage": "20Gi" + }, + "accessModes": [ + "ReadWriteOnce" + ], + "persistentVolumeReclaimPolicy": "Retain", + "storageClassName": "", + "hostPath": { + "path": "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/scope-state/lowkey-vault", + "type": "DirectoryOrCreate" + }, + "claimRef": { + "name": "lowkey-vault", + "namespace": "scope-dev" + } + } + }, + { + "apiVersion": "v1", + "kind": "PersistentVolumeClaim", + "metadata": { + "name": "lowkey-vault", + "namespace": "scope-dev" + }, + "spec": { + "storageClassName": "", + "volumeName": "scope-dev-lowkey-vault", + "accessModes": [ + "ReadWriteOnce" + ], + "resources": { + "requests": { + "storage": "20Gi" + } + } + } + }, + { + "apiVersion": "v1", + "kind": "PersistentVolume", + "metadata": { + "name": "scope-dev-entra-local" + }, + "spec": { + "capacity": { + "storage": "20Gi" + }, + "accessModes": [ + "ReadWriteOnce" + ], + "persistentVolumeReclaimPolicy": "Retain", + "storageClassName": "", + "hostPath": { + "path": "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/scope-state/entra-local", + "type": "DirectoryOrCreate" + }, + "claimRef": { + "name": "entra-local", + "namespace": "scope-dev" + } + } + }, + { + "apiVersion": "v1", + "kind": "PersistentVolumeClaim", + "metadata": { + "name": "entra-local", + "namespace": "scope-dev" + }, + "spec": { + "storageClassName": "", + "volumeName": "scope-dev-entra-local", + "accessModes": [ + "ReadWriteOnce" + ], + "resources": { + "requests": { + "storage": "20Gi" + } + } + } + }, + { + "apiVersion": "v1", + "kind": "PersistentVolume", + "metadata": { + "name": "scope-dev-agent-workspaces" + }, + "spec": { + "capacity": { + "storage": "20Gi" + }, + "accessModes": [ + "ReadWriteOnce" + ], + "persistentVolumeReclaimPolicy": "Retain", + "storageClassName": "", + "hostPath": { + "path": "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/scope-state/agent-workspaces", + "type": "DirectoryOrCreate" + }, + "claimRef": { + "name": "agent-workspaces", + "namespace": "scope-dev" + } + } + }, + { + "apiVersion": "v1", + "kind": "PersistentVolumeClaim", + "metadata": { + "name": "agent-workspaces", + "namespace": "scope-dev" + }, + "spec": { + "storageClassName": "", + "volumeName": "scope-dev-agent-workspaces", + "accessModes": [ + "ReadWriteOnce" + ], + "resources": { + "requests": { + "storage": "20Gi" + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "mongodb", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "mongodb", + "namespace": "scope-dev" + }, + "spec": { + "selector": { + "app": "mongodb" + }, + "ports": [ + { + "name": "http", + "port": 27017, + "targetPort": 27017 + } + ] + } + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "mongodb", + "namespace": "scope-dev" + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "app": "mongodb" + } + }, + "template": { + "metadata": { + "labels": { + "app": "mongodb" + } + }, + "spec": { + "serviceAccountName": "mongodb", + "automountServiceAccountToken": false, + "terminationGracePeriodSeconds": 120, + "containers": [ + { + "name": "mongodb", + "image": "mongo:7.0.17", + "imagePullPolicy": "IfNotPresent", + "resources": { + "requests": { + "cpu": "100m", + "memory": "128Mi" + }, + "limits": { + "cpu": "2", + "memory": "2Gi" + } + }, + "command": [ + "mongod", + "--replSet", + "rs0", + "--bind_ip_all", + "--dbpath", + "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/data/db" + ], + "volumeMounts": [ + { + "name": "data", + "mountPath": "/data" + } + ], + "readinessProbe": { + "exec": { + "command": [ + "mongosh", + "--quiet", + "--eval", + "db.adminCommand({ping:1}).ok || quit(1)" + ] + }, + "periodSeconds": 3 + } + } + ], + "volumes": [ + { + "name": "data", + "persistentVolumeClaim": { + "claimName": "mongodb" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "mongo-init", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": { + "name": "mongo-init", + "namespace": "scope-dev" + }, + "spec": { + "suspend": false, + "backoffLimit": 2, + "activeDeadlineSeconds": 600, + "template": { + "metadata": { + "labels": { + "app": "mongo-init" + } + }, + "spec": { + "serviceAccountName": "mongo-init", + "automountServiceAccountToken": false, + "restartPolicy": "Never", + "containers": [ + { + "name": "mongo-init", + "image": "mongo:7.0.17", + "imagePullPolicy": "IfNotPresent", + "command": [ + "mongosh", + "--host", + "mongodb", + "--quiet", + "--eval", + "for(let attempt=0;attempt<90;attempt++){try{try{rs.status()}catch(error){if(error.code!==94)throw error;rs.initiate({_id:'rs0',members:[{_id:0,host:'mongodb:27017'}]})}if(db.hello().isWritablePrimary)quit(0)}catch(error){print(error.message)}await new Promise(resolve=>setTimeout(resolve,2000))}quit(1)" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "redis", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "redis", + "namespace": "scope-dev" + }, + "spec": { + "selector": { + "app": "redis" + }, + "ports": [ + { + "name": "http", + "port": 6379, + "targetPort": 6379 + } + ] + } + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "redis", + "namespace": "scope-dev" + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "app": "redis" + } + }, + "template": { + "metadata": { + "labels": { + "app": "redis" + } + }, + "spec": { + "serviceAccountName": "redis", + "automountServiceAccountToken": false, + "terminationGracePeriodSeconds": 120, + "containers": [ + { + "name": "redis", + "image": "redis:7.4.2-alpine", + "imagePullPolicy": "IfNotPresent", + "resources": { + "requests": { + "cpu": "100m", + "memory": "128Mi" + }, + "limits": { + "cpu": "2", + "memory": "2Gi" + } + }, + "command": [ + "redis-server", + "--appendonly", + "yes" + ], + "volumeMounts": [ + { + "name": "data", + "mountPath": "/data" + } + ], + "readinessProbe": { + "exec": { + "command": [ + "redis-cli", + "ping" + ] + }, + "periodSeconds": 3 + } + } + ], + "volumes": [ + { + "name": "data", + "persistentVolumeClaim": { + "claimName": "redis" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "azurite", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "azurite", + "namespace": "scope-dev" + }, + "spec": { + "selector": { + "app": "azurite" + }, + "ports": [ + { + "name": "port-10000", + "port": 10000 + }, + { + "name": "port-10001", + "port": 10001 + }, + { + "name": "port-10002", + "port": 10002 + } + ] + } + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "azurite", + "namespace": "scope-dev" + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "app": "azurite" + } + }, + "template": { + "metadata": { + "labels": { + "app": "azurite" + } + }, + "spec": { + "serviceAccountName": "azurite", + "automountServiceAccountToken": false, + "terminationGracePeriodSeconds": 120, + "containers": [ + { + "name": "azurite", + "image": "mcr.microsoft.com/azure-storage/azurite:3.29.0", + "imagePullPolicy": "IfNotPresent", + "resources": { + "requests": { + "cpu": "100m", + "memory": "128Mi" + }, + "limits": { + "cpu": "2", + "memory": "2Gi" + } + }, + "command": [ + "azurite", + "--skipApiVersionCheck", + "--loose", + "--blobHost", + "0.0.0.0", + "--queueHost", + "0.0.0.0", + "--tableHost", + "0.0.0.0", + "--location", + "/data" + ], + "volumeMounts": [ + { + "name": "data", + "mountPath": "/data" + } + ], + "readinessProbe": { + "tcpSocket": { + "port": 10001 + }, + "periodSeconds": 3 + } + } + ], + "volumes": [ + { + "name": "data", + "persistentVolumeClaim": { + "claimName": "azurite" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "entra-local", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "entra-local", + "namespace": "scope-dev" + }, + "spec": { + "selector": { + "app": "entra-local" + }, + "ports": [ + { + "name": "http", + "port": 8443, + "targetPort": 8443 + } + ] + } + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "entra-local", + "namespace": "scope-dev" + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "app": "entra-local" + } + }, + "template": { + "metadata": { + "labels": { + "app": "entra-local" + } + }, + "spec": { + "serviceAccountName": "entra-local", + "automountServiceAccountToken": false, + "terminationGracePeriodSeconds": 120, + "containers": [ + { + "name": "entra-local", + "image": "ghcr.io/cmaneu/entra-local@sha256:70584ef110914d100409cb3d63a63548ccdde10ca780f9751755f1482dec5d7e", + "imagePullPolicy": "IfNotPresent", + "resources": { + "requests": { + "cpu": "100m", + "memory": "128Mi" + }, + "limits": { + "cpu": "2", + "memory": "2Gi" + } + }, + "env": [ + { + "name": "PUBLIC_ORIGIN", + "value": "https://localhost:8443" + }, + { + "name": "ISSUER", + "value": "https://localhost:8443/11111111-1111-1111-1111-111111111111/v2.0" + }, + { + "name": "TLS_ENABLED", + "value": "true" + }, + { + "name": "TLS_CERT", + "value": "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/certs/edge.pem" + }, + { + "name": "TLS_KEY", + "value": "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/certs/edge-key.pem" + }, + { + "name": "TENANT_ID", + "value": "11111111-1111-1111-1111-111111111111" + } + ], + "volumeMounts": [ + { + "name": "certificates", + "mountPath": "/certs", + "readOnly": true + }, + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + }, + { + "name": "data", + "mountPath": "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/app/data" + } + ], + "readinessProbe": { + "tcpSocket": { + "port": 8443 + }, + "periodSeconds": 3 + } + } + ], + "volumes": [ + { + "name": "certificates", + "secret": { + "secretName": "development-certificates" + } + }, + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + }, + { + "name": "data", + "persistentVolumeClaim": { + "claimName": "entra-local" + } + } + ], + "securityContext": { + "fsGroup": 1000 + }, + "initContainers": [ + { + "name": "permissions", + "image": "ghcr.io/cmaneu/entra-local@sha256:70584ef110914d100409cb3d63a63548ccdde10ca780f9751755f1482dec5d7e", + "securityContext": { + "runAsUser": 0 + }, + "command": [ + "chown", + "1000:1000", + "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/app/data" + ], + "volumeMounts": [ + { + "name": "data", + "mountPath": "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/app/data" + } + ] + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "lowkey-vault", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "lowkey-vault", + "namespace": "scope-dev" + }, + "spec": { + "selector": { + "app": "lowkey-vault" + }, + "ports": [ + { + "name": "https", + "port": 8443 + }, + { + "name": "identity", + "port": 8080 + } + ] + } + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "lowkey-vault", + "namespace": "scope-dev" + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "app": "lowkey-vault" + } + }, + "template": { + "metadata": { + "labels": { + "app": "lowkey-vault" + } + }, + "spec": { + "serviceAccountName": "lowkey-vault", + "automountServiceAccountToken": false, + "terminationGracePeriodSeconds": 120, + "containers": [ + { + "name": "lowkey-vault", + "image": "nagyesta/lowkey-vault:7.2.0-ubi10-minimal", + "imagePullPolicy": "IfNotPresent", + "resources": { + "requests": { + "cpu": "100m", + "memory": "128Mi" + }, + "limits": { + "cpu": "2", + "memory": "2Gi" + } + }, + "env": [ + { + "name": "SERVER_SSL_KEY_STORE", + "value": "file:/certs/lowkey.p12" + }, + { + "name": "SERVER_SSL_KEY_STORE_PASSWORD", + "value": "scope-local-development" + }, + { + "name": "LOWKEY_ARGS", + "value": "--server.port=8443 --LOWKEY_VAULT_NAMES=- --LOWKEY_EXPORT_LOCATION=/data/export.json --LOWKEY_IMPORT_LOCATION=/data/export.json" + } + ], + "volumeMounts": [ + { + "name": "certificates", + "mountPath": "/certs", + "readOnly": true + }, + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + }, + { + "name": "data", + "mountPath": "/data" + } + ], + "readinessProbe": { + "tcpSocket": { + "port": 8443 + }, + "periodSeconds": 5 + }, + "command": [ + "/bin/sh", + "-c", + "[ -f /data/export.json ] || printf '%s\\n' '{\"vaults\":[{\"attributes\":{\"baseUri\":\"https://lowkey-vault:8443\",\"recoveryLevel\":\"Recoverable+Purgeable\",\"recoverableDays\":90,\"created\":0,\"deleted\":null},\"keys\":{},\"secrets\":{},\"certificates\":{}}]}' > /data/export.json; exec java -jar /lowkey-vault.jar $LOWKEY_ARGS" + ] + } + ], + "volumes": [ + { + "name": "certificates", + "secret": { + "secretName": "development-certificates" + } + }, + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + }, + { + "name": "data", + "persistentVolumeClaim": { + "claimName": "lowkey-vault" + } + } + ], + "securityContext": { + "runAsUser": 1000, + "runAsGroup": 1000, + "fsGroup": 1000 + }, + "initContainers": [ + { + "name": "permissions", + "image": "nagyesta/lowkey-vault:7.2.0-ubi10-minimal", + "securityContext": { + "runAsUser": 0 + }, + "command": [ + "chown", + "1000:1000", + "/data" + ], + "volumeMounts": [ + { + "name": "data", + "mountPath": "/data" + } + ] + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "api", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "api", + "namespace": "scope-dev" + }, + "spec": { + "selector": { + "app": "api" + }, + "ports": [ + { + "name": "http", + "port": 80, + "targetPort": 80 + } + ] + } + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "api", + "namespace": "scope-dev" + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "app": "api" + } + }, + "template": { + "metadata": { + "labels": { + "app": "api" + } + }, + "spec": { + "serviceAccountName": "api", + "automountServiceAccountToken": false, + "terminationGracePeriodSeconds": 120, + "containers": [ + { + "name": "api", + "image": "scope-local/api:development", + "imagePullPolicy": "Never", + "resources": { + "requests": { + "cpu": "100m", + "memory": "128Mi" + }, + "limits": { + "cpu": "2", + "memory": "2Gi" + } + }, + "workingDir": "/app", + "command": [ + "node", + "--watch", + "--conditions=source", + "--enable-source-maps", + "--import", + "tsx", + "apps/api/src/index.ts" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "env": [ + { + "name": "PORT", + "value": "80" + }, + { + "name": "NODE_EXTRA_CA_CERTS", + "value": "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/ca/rootCA.pem" + }, + { + "name": "SCHEDULER_TARGET_QUEUE_DEPTH", + "value": "1" + } + ], + "ports": [ + { + "containerPort": 80 + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ], + "startupProbe": { + "tcpSocket": { + "port": 80 + }, + "periodSeconds": 3, + "failureThreshold": 100 + }, + "readinessProbe": { + "httpGet": { + "path": "/ready", + "port": 80 + }, + "periodSeconds": 3 + } + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "portal", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "portal", + "namespace": "scope-dev" + }, + "spec": { + "selector": { + "app": "portal" + }, + "ports": [ + { + "name": "http", + "port": 5100, + "targetPort": 5100 + } + ] + } + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "portal", + "namespace": "scope-dev" + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "app": "portal" + } + }, + "template": { + "metadata": { + "labels": { + "app": "portal" + } + }, + "spec": { + "serviceAccountName": "portal", + "automountServiceAccountToken": false, + "terminationGracePeriodSeconds": 120, + "containers": [ + { + "name": "portal", + "image": "scope-local/tools:development", + "imagePullPolicy": "Never", + "resources": { + "requests": { + "cpu": "100m", + "memory": "128Mi" + }, + "limits": { + "cpu": "2", + "memory": "2Gi" + } + }, + "workingDir": "/app", + "command": [ + "pnpm", + "--filter", + "portal", + "dev", + "--host", + "0.0.0.0", + "--port", + "5100", + "--strictPort" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "env": [ + { + "name": "PORT", + "value": "5100" + }, + { + "name": "NODE_EXTRA_CA_CERTS", + "value": "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/ca/rootCA.pem" + }, + { + "name": "SCHEDULER_TARGET_QUEUE_DEPTH", + "value": "1" + } + ], + "ports": [ + { + "containerPort": 5100 + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ], + "startupProbe": { + "tcpSocket": { + "port": 5100 + }, + "periodSeconds": 3, + "failureThreshold": 100 + }, + "readinessProbe": { + "tcpSocket": { + "port": 5100 + }, + "periodSeconds": 3 + } + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "judge", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "judge", + "namespace": "scope-dev" + }, + "spec": { + "selector": { + "app": "judge" + }, + "ports": [ + { + "name": "http", + "port": 80, + "targetPort": 80 + } + ] + } + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "judge", + "namespace": "scope-dev" + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "app": "judge" + } + }, + "template": { + "metadata": { + "labels": { + "app": "judge" + } + }, + "spec": { + "serviceAccountName": "judge", + "automountServiceAccountToken": false, + "terminationGracePeriodSeconds": 120, + "containers": [ + { + "name": "judge", + "image": "scope-local/judge:development", + "imagePullPolicy": "Never", + "resources": { + "requests": { + "cpu": "100m", + "memory": "128Mi" + }, + "limits": { + "cpu": "2", + "memory": "2Gi" + } + }, + "workingDir": "/app", + "command": [ + "node", + "--watch", + "--conditions=source", + "--enable-source-maps", + "--import", + "tsx", + "apps/judge/src/index.ts" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "env": [ + { + "name": "PORT", + "value": "80" + }, + { + "name": "NODE_EXTRA_CA_CERTS", + "value": "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/ca/rootCA.pem" + }, + { + "name": "SCHEDULER_TARGET_QUEUE_DEPTH", + "value": "1" + } + ], + "ports": [ + { + "containerPort": 80 + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ], + "startupProbe": { + "tcpSocket": { + "port": 80 + }, + "periodSeconds": 3, + "failureThreshold": 100 + }, + "readinessProbe": { + "tcpSocket": { + "port": 80 + }, + "periodSeconds": 3 + } + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "token-manager", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "token-manager", + "namespace": "scope-dev" + }, + "spec": { + "selector": { + "app": "token-manager" + }, + "ports": [ + { + "name": "http", + "port": 80, + "targetPort": 80 + } + ] + } + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "token-manager", + "namespace": "scope-dev" + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "app": "token-manager" + } + }, + "template": { + "metadata": { + "labels": { + "app": "token-manager" + } + }, + "spec": { + "serviceAccountName": "token-manager", + "automountServiceAccountToken": false, + "terminationGracePeriodSeconds": 120, + "containers": [ + { + "name": "token-manager", + "image": "scope-local/token-manager:development", + "imagePullPolicy": "Never", + "resources": { + "requests": { + "cpu": "100m", + "memory": "128Mi" + }, + "limits": { + "cpu": "2", + "memory": "2Gi" + } + }, + "workingDir": "/app", + "command": [ + "node", + "--watch", + "--conditions=source", + "--enable-source-maps", + "--import", + "tsx", + "apps/token-manager/src/index.ts" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "env": [ + { + "name": "PORT", + "value": "80" + }, + { + "name": "NODE_EXTRA_CA_CERTS", + "value": "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/ca/rootCA.pem" + }, + { + "name": "SCHEDULER_TARGET_QUEUE_DEPTH", + "value": "1" + } + ], + "ports": [ + { + "containerPort": 80 + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ], + "startupProbe": { + "tcpSocket": { + "port": 80 + }, + "periodSeconds": 3, + "failureThreshold": 100 + }, + "readinessProbe": { + "tcpSocket": { + "port": 80 + }, + "periodSeconds": 3 + } + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "scheduler", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "scheduler", + "namespace": "scope-dev" + }, + "spec": { + "selector": { + "app": "scheduler" + }, + "ports": [ + { + "name": "http", + "port": 80, + "targetPort": 80 + } + ] + } + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "scheduler", + "namespace": "scope-dev" + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "app": "scheduler" + } + }, + "template": { + "metadata": { + "labels": { + "app": "scheduler" + } + }, + "spec": { + "serviceAccountName": "scheduler", + "automountServiceAccountToken": false, + "terminationGracePeriodSeconds": 120, + "containers": [ + { + "name": "scheduler", + "image": "scope-local/scheduler:development", + "imagePullPolicy": "Never", + "resources": { + "requests": { + "cpu": "100m", + "memory": "128Mi" + }, + "limits": { + "cpu": "2", + "memory": "2Gi" + } + }, + "workingDir": "/app", + "command": [ + "node", + "--watch", + "--conditions=source", + "--enable-source-maps", + "--import", + "tsx", + "apps/scheduler/src/index.ts" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "env": [ + { + "name": "PORT", + "value": "80" + }, + { + "name": "NODE_EXTRA_CA_CERTS", + "value": "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/ca/rootCA.pem" + }, + { + "name": "SCHEDULER_TARGET_QUEUE_DEPTH", + "value": "1" + } + ], + "ports": [ + { + "containerPort": 80 + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ], + "startupProbe": { + "tcpSocket": { + "port": 80 + }, + "periodSeconds": 3, + "failureThreshold": 100 + }, + "readinessProbe": { + "tcpSocket": { + "port": 80 + }, + "periodSeconds": 3 + } + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "gateway", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "gateway", + "namespace": "scope-dev" + }, + "spec": { + "selector": { + "app": "gateway" + }, + "ports": [ + { + "name": "http", + "port": 18000, + "targetPort": 18000 + } + ] + } + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "gateway", + "namespace": "scope-dev" + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "app": "gateway" + } + }, + "template": { + "metadata": { + "labels": { + "app": "gateway" + } + }, + "spec": { + "serviceAccountName": "gateway", + "automountServiceAccountToken": false, + "terminationGracePeriodSeconds": 120, + "containers": [ + { + "name": "gateway", + "image": "scope-local/gateway:development", + "imagePullPolicy": "Never", + "resources": { + "requests": { + "cpu": "100m", + "memory": "128Mi" + }, + "limits": { + "cpu": "2", + "memory": "2Gi" + } + }, + "ports": [ + { + "containerPort": 18000 + }, + { + "containerPort": 18897 + } + ], + "readinessProbe": { + "tcpSocket": { + "port": 18897 + }, + "periodSeconds": 5 + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "coder-acp-copilot", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "coder-acp-copilot", + "namespace": "scope-dev" + }, + "spec": { + "selector": { + "app": "coder-acp-copilot" + }, + "ports": [ + { + "name": "http", + "port": 80, + "targetPort": 80 + } + ] + } + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "coder-acp-copilot", + "namespace": "scope-dev" + }, + "spec": { + "replicas": 0, + "selector": { + "matchLabels": { + "app": "coder-acp-copilot" + } + }, + "template": { + "metadata": { + "labels": { + "app": "coder-acp-copilot" + } + }, + "spec": { + "serviceAccountName": "coder-acp-copilot", + "automountServiceAccountToken": false, + "terminationGracePeriodSeconds": 120, + "containers": [ + { + "name": "coder-acp-copilot", + "image": "scope-local/coder-acp-copilot:development", + "imagePullPolicy": "Never", + "resources": { + "requests": { + "cpu": "100m", + "memory": "128Mi" + }, + "limits": { + "cpu": "2", + "memory": "2Gi" + } + }, + "workingDir": "/app", + "command": [ + "node", + "--conditions=source", + "--enable-source-maps", + "--import", + "tsx", + "apps/workers/coder-acp-copilot/src/index.ts" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "env": [ + { + "name": "PORT", + "value": "80" + }, + { + "name": "NODE_EXTRA_CA_CERTS", + "value": "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/ca/rootCA.pem" + }, + { + "name": "SCHEDULER_TARGET_QUEUE_DEPTH", + "value": "1" + } + ], + "ports": [ + { + "containerPort": 80 + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "coder-acp-claude-code", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "coder-acp-claude-code", + "namespace": "scope-dev" + }, + "spec": { + "selector": { + "app": "coder-acp-claude-code" + }, + "ports": [ + { + "name": "http", + "port": 80, + "targetPort": 80 + } + ] + } + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "coder-acp-claude-code", + "namespace": "scope-dev" + }, + "spec": { + "replicas": 0, + "selector": { + "matchLabels": { + "app": "coder-acp-claude-code" + } + }, + "template": { + "metadata": { + "labels": { + "app": "coder-acp-claude-code" + } + }, + "spec": { + "serviceAccountName": "coder-acp-claude-code", + "automountServiceAccountToken": false, + "terminationGracePeriodSeconds": 120, + "containers": [ + { + "name": "coder-acp-claude-code", + "image": "scope-local/coder-acp-claude-code:development", + "imagePullPolicy": "Never", + "resources": { + "requests": { + "cpu": "100m", + "memory": "128Mi" + }, + "limits": { + "cpu": "2", + "memory": "2Gi" + } + }, + "workingDir": "/app", + "command": [ + "node", + "--conditions=source", + "--enable-source-maps", + "--import", + "tsx", + "apps/workers/coder-acp-claude-code/src/index.ts" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "env": [ + { + "name": "PORT", + "value": "80" + }, + { + "name": "NODE_EXTRA_CA_CERTS", + "value": "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/ca/rootCA.pem" + }, + { + "name": "SCHEDULER_TARGET_QUEUE_DEPTH", + "value": "1" + } + ], + "ports": [ + { + "containerPort": 80 + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "report-generator", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "report-generator", + "namespace": "scope-dev" + }, + "spec": { + "selector": { + "app": "report-generator" + }, + "ports": [ + { + "name": "http", + "port": 80, + "targetPort": 80 + } + ] + } + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "report-generator", + "namespace": "scope-dev" + }, + "spec": { + "replicas": 0, + "selector": { + "matchLabels": { + "app": "report-generator" + } + }, + "template": { + "metadata": { + "labels": { + "app": "report-generator" + } + }, + "spec": { + "serviceAccountName": "report-generator", + "automountServiceAccountToken": false, + "terminationGracePeriodSeconds": 120, + "containers": [ + { + "name": "report-generator", + "image": "scope-local/report-generator:development", + "imagePullPolicy": "Never", + "resources": { + "requests": { + "cpu": "100m", + "memory": "128Mi" + }, + "limits": { + "cpu": "2", + "memory": "2Gi" + } + }, + "workingDir": "/app", + "command": [ + "node", + "--conditions=source", + "--enable-source-maps", + "--import", + "tsx", + "apps/workers/report-generator/src/index.ts" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "env": [ + { + "name": "PORT", + "value": "80" + }, + { + "name": "NODE_EXTRA_CA_CERTS", + "value": "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/ca/rootCA.pem" + }, + { + "name": "SCHEDULER_TARGET_QUEUE_DEPTH", + "value": "1" + } + ], + "ports": [ + { + "containerPort": 80 + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "post-processor", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "post-processor", + "namespace": "scope-dev" + }, + "spec": { + "selector": { + "app": "post-processor" + }, + "ports": [ + { + "name": "http", + "port": 80, + "targetPort": 80 + } + ] + } + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "post-processor", + "namespace": "scope-dev" + }, + "spec": { + "replicas": 0, + "selector": { + "matchLabels": { + "app": "post-processor" + } + }, + "template": { + "metadata": { + "labels": { + "app": "post-processor" + } + }, + "spec": { + "serviceAccountName": "post-processor", + "automountServiceAccountToken": false, + "terminationGracePeriodSeconds": 120, + "containers": [ + { + "name": "post-processor", + "image": "scope-local/post-processor:development", + "imagePullPolicy": "Never", + "resources": { + "requests": { + "cpu": "100m", + "memory": "128Mi" + }, + "limits": { + "cpu": "2", + "memory": "2Gi" + } + }, + "workingDir": "/app", + "command": [ + "node", + "--conditions=source", + "--enable-source-maps", + "--import", + "tsx", + "apps/workers/post-processor/src/index.ts" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "env": [ + { + "name": "PORT", + "value": "80" + }, + { + "name": "NODE_EXTRA_CA_CERTS", + "value": "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/ca/rootCA.pem" + }, + { + "name": "SCHEDULER_TARGET_QUEUE_DEPTH", + "value": "1" + } + ], + "ports": [ + { + "containerPort": 80 + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "model-scanner-copilot", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": { + "name": "model-scanner-copilot", + "namespace": "scope-dev" + }, + "spec": { + "suspend": true, + "backoffLimit": 2, + "activeDeadlineSeconds": 600, + "template": { + "metadata": { + "labels": { + "app": "model-scanner-copilot" + } + }, + "spec": { + "serviceAccountName": "model-scanner-copilot", + "automountServiceAccountToken": false, + "restartPolicy": "Never", + "containers": [ + { + "name": "model-scanner-copilot", + "image": "scope-local/model-scanner-copilot:development", + "imagePullPolicy": "Never", + "command": [ + "node", + "--conditions=source", + "--enable-source-maps", + "--import", + "tsx", + "apps/model-scanners/copilot/src/index.ts" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "model-scanner-anthropic", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": { + "name": "model-scanner-anthropic", + "namespace": "scope-dev" + }, + "spec": { + "suspend": true, + "backoffLimit": 2, + "activeDeadlineSeconds": 600, + "template": { + "metadata": { + "labels": { + "app": "model-scanner-anthropic" + } + }, + "spec": { + "serviceAccountName": "model-scanner-anthropic", + "automountServiceAccountToken": false, + "restartPolicy": "Never", + "containers": [ + { + "name": "model-scanner-anthropic", + "image": "scope-local/model-scanner-anthropic:development", + "imagePullPolicy": "Never", + "command": [ + "node", + "--conditions=source", + "--enable-source-maps", + "--import", + "tsx", + "apps/model-scanners/anthropic/src/index.ts" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "version-checker-acp-copilot", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": { + "name": "version-checker-acp-copilot", + "namespace": "scope-dev" + }, + "spec": { + "suspend": true, + "backoffLimit": 2, + "activeDeadlineSeconds": 600, + "template": { + "metadata": { + "labels": { + "app": "version-checker-acp-copilot" + } + }, + "spec": { + "serviceAccountName": "version-checker-acp-copilot", + "automountServiceAccountToken": false, + "restartPolicy": "Never", + "containers": [ + { + "name": "version-checker-acp-copilot", + "image": "scope-local/tools:development", + "imagePullPolicy": "Never", + "command": [ + "node", + "--conditions=source", + "--enable-source-maps", + "--import", + "tsx", + "apps/version-checkers/acp-copilot/src/check-versions.ts" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "version-checker-claude-code", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": { + "name": "version-checker-claude-code", + "namespace": "scope-dev" + }, + "spec": { + "suspend": true, + "backoffLimit": 2, + "activeDeadlineSeconds": 600, + "template": { + "metadata": { + "labels": { + "app": "version-checker-claude-code" + } + }, + "spec": { + "serviceAccountName": "version-checker-claude-code", + "automountServiceAccountToken": false, + "restartPolicy": "Never", + "containers": [ + { + "name": "version-checker-claude-code", + "image": "scope-local/tools:development", + "imagePullPolicy": "Never", + "command": [ + "node", + "--conditions=source", + "--enable-source-maps", + "--import", + "tsx", + "apps/version-checkers/claude-code/src/check-versions.ts" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "github-cookie-updater", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": { + "name": "github-cookie-updater", + "namespace": "scope-dev" + }, + "spec": { + "suspend": true, + "backoffLimit": 2, + "activeDeadlineSeconds": 600, + "template": { + "metadata": { + "labels": { + "app": "github-cookie-updater" + } + }, + "spec": { + "serviceAccountName": "github-cookie-updater", + "automountServiceAccountToken": false, + "restartPolicy": "Never", + "containers": [ + { + "name": "github-cookie-updater", + "image": "scope-local/tools:development", + "imagePullPolicy": "Never", + "command": [ + "node", + "--conditions=source", + "--enable-source-maps", + "--import", + "tsx", + "apps/key-updaters/github-cookie-updater/src/github-cookie-updater.ts" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "cli", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": { + "name": "cli", + "namespace": "scope-dev" + }, + "spec": { + "suspend": true, + "backoffLimit": 2, + "activeDeadlineSeconds": 600, + "template": { + "metadata": { + "labels": { + "app": "cli" + } + }, + "spec": { + "serviceAccountName": "cli", + "automountServiceAccountToken": false, + "restartPolicy": "Never", + "containers": [ + { + "name": "cli", + "image": "scope-local/tools:development", + "imagePullPolicy": "Never", + "command": [ + "node", + "--conditions=source", + "--enable-source-maps", + "--import", + "tsx", + "apps/cli/src/index.ts", + "--help" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "db-migrations", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": { + "name": "db-migrations", + "namespace": "scope-dev" + }, + "spec": { + "suspend": true, + "backoffLimit": 2, + "activeDeadlineSeconds": 600, + "template": { + "metadata": { + "labels": { + "app": "db-migrations" + } + }, + "spec": { + "serviceAccountName": "db-migrations", + "automountServiceAccountToken": false, + "restartPolicy": "Never", + "containers": [ + { + "name": "db-migrations", + "image": "scope-local/tools:development", + "imagePullPolicy": "Never", + "command": [ + "node", + "--conditions=source", + "--enable-source-maps", + "--import", + "tsx", + "packages/db-migrations/src/migrate.ts", + "up" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "tests", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": { + "name": "tests", + "namespace": "scope-dev" + }, + "spec": { + "suspend": true, + "backoffLimit": 2, + "activeDeadlineSeconds": 600, + "template": { + "metadata": { + "labels": { + "app": "tests" + } + }, + "spec": { + "serviceAccountName": "tests", + "automountServiceAccountToken": false, + "restartPolicy": "Never", + "containers": [ + { + "name": "tests", + "image": "scope-local/tools:development", + "imagePullPolicy": "Never", + "command": [ + "pnpm", + "exec", + "vitest", + "run" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "prompt-evaluations", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": { + "name": "prompt-evaluations", + "namespace": "scope-dev" + }, + "spec": { + "suspend": true, + "backoffLimit": 2, + "activeDeadlineSeconds": 600, + "template": { + "metadata": { + "labels": { + "app": "prompt-evaluations" + } + }, + "spec": { + "serviceAccountName": "prompt-evaluations", + "automountServiceAccountToken": false, + "restartPolicy": "Never", + "containers": [ + { + "name": "prompt-evaluations", + "image": "scope-local/tools:development", + "imagePullPolicy": "Never", + "command": [ + "pnpm", + "eval:static-prompts:smoke" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "storybook", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": { + "name": "storybook", + "namespace": "scope-dev" + }, + "spec": { + "suspend": true, + "backoffLimit": 2, + "activeDeadlineSeconds": 600, + "template": { + "metadata": { + "labels": { + "app": "storybook" + } + }, + "spec": { + "serviceAccountName": "storybook", + "automountServiceAccountToken": false, + "restartPolicy": "Never", + "containers": [ + { + "name": "storybook", + "image": "scope-local/tools:development", + "imagePullPolicy": "Never", + "command": [ + "pnpm", + "--filter", + "portal", + "exec", + "storybook", + "dev", + "--host", + "0.0.0.0", + "--port", + "6100", + "--no-open" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "website", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": { + "name": "website", + "namespace": "scope-dev" + }, + "spec": { + "suspend": true, + "backoffLimit": 2, + "activeDeadlineSeconds": 600, + "template": { + "metadata": { + "labels": { + "app": "website" + } + }, + "spec": { + "serviceAccountName": "website", + "automountServiceAccountToken": false, + "restartPolicy": "Never", + "containers": [ + { + "name": "website", + "image": "scope-local/tools:development", + "imagePullPolicy": "Never", + "command": [ + "pnpm", + "--dir", + "website", + "exec", + "astro", + "dev", + "--host", + "0.0.0.0" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "dev-edge", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "dev-edge", + "namespace": "scope-dev" + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "app": "dev-edge" + } + }, + "template": { + "metadata": { + "labels": { + "app": "dev-edge" + } + }, + "spec": { + "serviceAccountName": "dev-edge", + "automountServiceAccountToken": false, + "terminationGracePeriodSeconds": 120, + "containers": [ + { + "name": "dev-edge", + "image": "nginx@sha256:5b4900b042ccfa8b0a73df622c3a60f2322faeb2be800cbee5aa7b44d241649e", + "imagePullPolicy": "IfNotPresent", + "resources": { + "requests": { + "cpu": "100m", + "memory": "128Mi" + }, + "limits": { + "cpu": "2", + "memory": "2Gi" + } + }, + "volumeMounts": [ + { + "name": "certificates", + "mountPath": "/certs", + "readOnly": true + }, + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + }, + { + "name": "config", + "mountPath": "/etc/nginx/conf.d", + "readOnly": true + } + ], + "readinessProbe": { + "tcpSocket": { + "port": 8080 + }, + "periodSeconds": 3 + } + } + ], + "volumes": [ + { + "name": "certificates", + "secret": { + "secretName": "development-certificates" + } + }, + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + }, + { + "name": "config", + "configMap": { + "name": "dev-edge" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "name": "dev-edge", + "namespace": "scope-dev" + }, + "spec": { + "type": "NodePort", + "selector": { + "app": "dev-edge" + }, + "ports": [ + { + "name": "edge", + "port": 8080, + "targetPort": 8080, + "nodePort": 30080 + } + ] + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "storage-init", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": { + "name": "storage-init", + "namespace": "scope-dev" + }, + "spec": { + "suspend": false, + "backoffLimit": 2, + "activeDeadlineSeconds": 600, + "template": { + "metadata": { + "labels": { + "app": "storage-init" + } + }, + "spec": { + "serviceAccountName": "storage-init", + "automountServiceAccountToken": false, + "restartPolicy": "Never", + "containers": [ + { + "name": "storage-init", + "image": "scope-local/tools:development", + "imagePullPolicy": "Never", + "command": [ + "node", + "--import", + "tsx", + "scripts/dev/bootstrap.ts", + "storage-init" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "redirect-init", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": { + "name": "redirect-init", + "namespace": "scope-dev" + }, + "spec": { + "suspend": false, + "backoffLimit": 2, + "activeDeadlineSeconds": 600, + "template": { + "metadata": { + "labels": { + "app": "redirect-init" + } + }, + "spec": { + "serviceAccountName": "redirect-init", + "automountServiceAccountToken": false, + "restartPolicy": "Never", + "containers": [ + { + "name": "redirect-init", + "image": "scope-local/tools:development", + "imagePullPolicy": "Never", + "command": [ + "node", + "--import", + "tsx", + "scripts/dev/bootstrap.ts", + "redirect-init" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "db-migrate", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": { + "name": "db-migrate", + "namespace": "scope-dev" + }, + "spec": { + "suspend": false, + "backoffLimit": 2, + "activeDeadlineSeconds": 600, + "template": { + "metadata": { + "labels": { + "app": "db-migrate" + } + }, + "spec": { + "serviceAccountName": "db-migrate", + "automountServiceAccountToken": false, + "restartPolicy": "Never", + "containers": [ + { + "name": "db-migrate", + "image": "scope-local/tools:development", + "imagePullPolicy": "Never", + "command": [ + "node", + "--import", + "tsx", + "scripts/dev/bootstrap.ts", + "db-migrate" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + }, + { + "apiVersion": "v1", + "kind": "ServiceAccount", + "metadata": { + "name": "register-agents", + "namespace": "scope-dev" + }, + "automountServiceAccountToken": false + }, + { + "apiVersion": "batch/v1", + "kind": "Job", + "metadata": { + "name": "register-agents", + "namespace": "scope-dev" + }, + "spec": { + "suspend": false, + "backoffLimit": 2, + "activeDeadlineSeconds": 600, + "template": { + "metadata": { + "labels": { + "app": "register-agents" + } + }, + "spec": { + "serviceAccountName": "register-agents", + "automountServiceAccountToken": false, + "restartPolicy": "Never", + "containers": [ + { + "name": "register-agents", + "image": "scope-local/tools:development", + "imagePullPolicy": "Never", + "command": [ + "node", + "--import", + "tsx", + "scripts/dev/bootstrap.ts", + "register-agents" + ], + "envFrom": [ + { + "configMapRef": { + "name": "scope-runtime" + } + } + ], + "volumeMounts": [ + { + "name": "public-ca", + "mountPath": "/ca", + "readOnly": true + } + ] + } + ], + "volumes": [ + { + "name": "public-ca", + "configMap": { + "name": "public-ca" + } + } + ] + } + } + } + } + ] +} \ No newline at end of file diff --git a/.devcontainer/kind/cluster.yaml b/.devcontainer/kind/cluster.yaml new file mode 100644 index 000000000..5d904e4e5 --- /dev/null +++ b/.devcontainer/kind/cluster.yaml @@ -0,0 +1,12 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +networking: + apiServerAddress: "127.0.0.1" +nodes: + - role: control-plane + image: kindest/node:v1.32.2@sha256:142f543559cc55d64e1ab9341df08e5ced84bd2e893736da8f51320f26f5950b + extraPortMappings: + - containerPort: 30080 + hostPort: 8080 + listenAddress: "127.0.0.1" + protocol: TCP \ No newline at end of file diff --git a/.devcontainer/kind/components/kubedock/kustomization.yaml b/.devcontainer/kind/components/kubedock/kustomization.yaml new file mode 100644 index 000000000..f7b64dc2c --- /dev/null +++ b/.devcontainer/kind/components/kubedock/kustomization.yaml @@ -0,0 +1,64 @@ +apiVersion: kustomize.config.k8s.io/v1alpha1 +kind: Component +resources: + - rbac.yaml +patches: + - target: + kind: Deployment + name: coder-acp-copilot|coder-acp-claude-code + patch: |- + - op: add + path: /spec/template/spec/volumes/- + value: + name: kubedock-socket + emptyDir: {} + - op: add + path: /spec/template/spec/volumes/- + value: + name: kubernetes-identity + projected: + sources: + - serviceAccountToken: + audience: https://kubernetes.default.svc.cluster.local + expirationSeconds: 600 + path: token + - configMap: + name: kube-root-ca.crt + items: + - key: ca.crt + path: ca.crt + - downwardAPI: + items: + - path: namespace + fieldRef: + fieldPath: metadata.namespace + - op: add + path: /spec/template/spec/containers/0/volumeMounts/- + value: + name: kubedock-socket + mountPath: /var/run/kubedock + - op: add + path: /spec/template/spec/containers/0/env/- + value: + name: DOCKER_HOST + value: unix:///var/run/kubedock/kubedock.sock + - op: add + path: /spec/template/spec/containers/0/env/- + value: + name: KUBEDOCK_ENABLED + value: "true" + - op: add + path: /spec/template/spec/containers/- + value: + name: kubedock + image: joyrex2001/kubedock:0.17.0@sha256:750ec7dd09b10cc4720d2e03e2f856cff6020369aa03b0d6f258c1e6a5129985 + args: ["server", "--unix-socket", "/var/run/kubedock/kubedock.sock", "--port-forward", "--namespace", "scope-dev-tasks", "--service-account", "kubedock-task", "--disable-dind", "--request-cpu", "100m,1", "--request-memory", "64Mi,512Mi", "--active-deadline-seconds", "3600"] + resources: + requests: { cpu: 50m, memory: 64Mi } + limits: { cpu: "1", memory: 512Mi } + volumeMounts: + - name: kubedock-socket + mountPath: /var/run/kubedock + - name: kubernetes-identity + mountPath: /var/run/secrets/kubernetes.io/serviceaccount + readOnly: true \ No newline at end of file diff --git a/.devcontainer/kind/components/kubedock/rbac.yaml b/.devcontainer/kind/components/kubedock/rbac.yaml new file mode 100644 index 000000000..c7cf02f57 --- /dev/null +++ b/.devcontainer/kind/components/kubedock/rbac.yaml @@ -0,0 +1,47 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: scope-dev-tasks + labels: + pod-security.kubernetes.io/enforce: baseline + pod-security.kubernetes.io/enforce-version: v1.32 +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: kubedock-task + namespace: scope-dev-tasks +automountServiceAccountToken: false +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: kubedock + namespace: scope-dev-tasks +rules: + - apiGroups: [""] + resources: [pods, services, configmaps, persistentvolumeclaims, events] + verbs: [get, list, watch, create, delete, patch, update] + - apiGroups: [""] + resources: [pods/log] + verbs: [get] + - apiGroups: [""] + resources: [pods/exec, pods/attach, pods/portforward] + verbs: [get, create] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: kubedock + namespace: scope-dev-tasks +subjects: + - kind: ServiceAccount + name: coder-acp-copilot + namespace: scope-dev + - kind: ServiceAccount + name: coder-acp-claude-code + namespace: scope-dev +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: kubedock \ No newline at end of file diff --git a/.devcontainer/kind/overlays/debug/kustomization.yaml b/.devcontainer/kind/overlays/debug/kustomization.yaml new file mode 100644 index 000000000..7b78782c8 --- /dev/null +++ b/.devcontainer/kind/overlays/debug/kustomization.yaml @@ -0,0 +1,12 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../fast +patches: + - target: + kind: Deployment + name: api + patch: |- + - op: add + path: /spec/template/spec/containers/0/command/1 + value: --inspect=0.0.0.0:9230 \ No newline at end of file diff --git a/.devcontainer/kind/overlays/fast/kustomization.yaml b/.devcontainer/kind/overlays/fast/kustomization.yaml new file mode 100644 index 000000000..9294daf3a --- /dev/null +++ b/.devcontainer/kind/overlays/fast/kustomization.yaml @@ -0,0 +1,12 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../../base +patches: + - target: + kind: Deployment + name: gateway|judge|scheduler|token-manager + patch: |- + - op: replace + path: /spec/replicas + value: 0 \ No newline at end of file diff --git a/.devcontainer/native.compose.yaml b/.devcontainer/native.compose.yaml new file mode 100644 index 000000000..3d331817d --- /dev/null +++ b/.devcontainer/native.compose.yaml @@ -0,0 +1,79 @@ +services: + mongodb: + image: mongo:7.0.17 + command: ["mongod", "--replSet", "rs0", "--bind_ip_all"] + ports: ["127.0.0.1:${MONGODB_PORT:-27000}:27017"] + volumes: ["mongodb:/data/db"] + healthcheck: + test: ["CMD", "mongosh", "--quiet", "--eval", "db.adminCommand({ping:1}).ok || quit(1)"] + interval: 2s + timeout: 5s + retries: 45 + mongo-init: + image: mongo:7.0.17 + depends_on: + mongodb: { condition: service_healthy } + entrypoint: ["mongosh", "--host", "mongodb", "--quiet", "--eval"] + command: + - "try { rs.status() } catch (error) { if (error.code !== 94) throw error; rs.initiate({_id:'rs0',members:[{_id:0,host:'mongodb:27017'}]}) }" + redis: + image: redis:7.4.2-alpine + command: ["redis-server", "--appendonly", "yes"] + ports: ["127.0.0.1:${REDIS_PORT:-6300}:6379"] + volumes: ["redis:/data"] + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 2s + timeout: 3s + retries: 30 + azurite: + image: mcr.microsoft.com/azure-storage/azurite:3.29.0 + command: ["azurite", "--loose", "--skipApiVersionCheck", "--blobHost", "0.0.0.0", "--queueHost", "0.0.0.0", "--tableHost", "0.0.0.0", "--location", "/data", "--silent"] + ports: + - "127.0.0.1:${AZURITE_BLOB_PORT:-10100}:10000" + - "127.0.0.1:${AZURITE_QUEUE_PORT:-10200}:10001" + - "127.0.0.1:${AZURITE_TABLE_PORT:-10300}:10002" + volumes: ["azurite:/data"] + healthcheck: + test: ["CMD", "node", "-e", "require('http').get('http://localhost:10001',r=>process.exit(r.statusCode===400?0:1)).on('error',()=>process.exit(1))"] + interval: 2s + timeout: 3s + retries: 30 + lowkey-init: + image: nagyesta/lowkey-vault:7.2.0-ubi10-minimal + user: "0:0" + entrypoint: ["chown", "1000:1000", "/data"] + volumes: ["lowkey:/data"] + lowkey-vault: + image: nagyesta/lowkey-vault:7.2.0-ubi10-minimal + user: "1000:1000" + depends_on: + lowkey-init: { condition: service_completed_successfully } + ports: + - "127.0.0.1:${LOWKEY_VAULT_PORT:-18444}:8443" + - "127.0.0.1:${LOWKEY_IDENTITY_PORT:-18082}:8080" + environment: + SERVER_SSL_KEY_STORE: file:/certs/lowkey.p12 + SERVER_SSL_KEY_STORE_PASSWORD: scope-local-development + SERVER_SSL_KEY_STORE_TYPE: PKCS12 + LOWKEY_ARGS: "--server.port=8443 --spring.main.banner-mode=off --LOWKEY_VAULT_NAMES=- --LOWKEY_IMPORT_LOCATION=/data/export.json --LOWKEY_EXPORT_LOCATION=/data/export.json" + LOWKEY_SEED_URI: "https://localhost:${LOWKEY_VAULT_PORT:-18444}" + entrypoint: + - /bin/sh + - -c + - >- + [ -f /data/export.json ] || printf '%s\n' "{\"vaults\":[{\"attributes\":{\"baseUri\":\"$$LOWKEY_SEED_URI\",\"recoveryLevel\":\"Recoverable+Purgeable\",\"recoverableDays\":90,\"created\":0,\"deleted\":null},\"keys\":{},\"secrets\":{},\"certificates\":{}}]}" > /data/export.json; + exec java -jar /lowkey-vault.jar $$LOWKEY_ARGS + volumes: + - lowkey:/data + - ${DEV_CERT_DIR:?required}:/certs:ro + healthcheck: + test: ["CMD", "curl", "--fail", "--silent", "--cacert", "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/certs/lowkey-ca.pem", "https://localhost:8443/ping"] + interval: 3s + timeout: 5s + retries: 60 +volumes: + mongodb: + redis: + azurite: + lowkey: \ No newline at end of file diff --git a/.devcontainer/runtime.Dockerfile b/.devcontainer/runtime.Dockerfile new file mode 100644 index 000000000..01b98fcf1 --- /dev/null +++ b/.devcontainer/runtime.Dockerfile @@ -0,0 +1,15 @@ +FROM node:22.22.0-bookworm@sha256:20a424ecd1d2064a44e12fe287bf3dae443aab31dc5e0c0cb6c74bef9c78911c +RUN apt-get update && apt-get install -y --no-install-recommends git curl ca-certificates python3 openssl \ + && rm -rf /var/lib/apt/lists/* +WORKDIR /app +COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ +RUN npm install -g "$(node -p 'require("./package.json").packageManager')" +COPY . . +RUN pnpm install --frozen-lockfile \ + && pnpm -r --filter './packages/**' --if-present build \ + && pnpm --dir website install --frozen-lockfile +RUN pnpm --filter github-auth exec playwright install --with-deps chromium \ + && pnpm --filter github-cookie-updater exec playwright install chromium \ + && pnpm --dir website exec playwright install chromium +ENV NODE_ENV=development +CMD ["pnpm", "exec", "vitest", "run"] \ No newline at end of file diff --git a/.devcontainer/skaffold.yaml b/.devcontainer/skaffold.yaml new file mode 100644 index 000000000..a1530a367 --- /dev/null +++ b/.devcontainer/skaffold.yaml @@ -0,0 +1,38 @@ +apiVersion: skaffold/v4beta11 +kind: Config +metadata: + name: scope-local-development +build: + local: + push: false + concurrency: 1 + useBuildkit: true + artifacts: + - image: scope-local/tools + context: .. + docker: + dockerfile: .devcontainer/runtime.Dockerfile + sync: + manual: + - src: apps/portal/src/**/* + dest: /app + - src: packages/*/src/**/* + dest: /app + - image: scope-local/api + context: .. + docker: + dockerfile: apps/api/Dockerfile + target: dev + sync: + manual: + - src: apps/api/src/**/* + dest: /app + - src: packages/*/src/**/* + dest: /app +manifests: + kustomize: + paths: + - ../.dev-state/runtime/kustomize +deploy: + kubectl: {} +portForward: [] \ No newline at end of file diff --git a/.devcontainer/spike/compose.yaml b/.devcontainer/spike/compose.yaml new file mode 100644 index 000000000..4b6dc7d45 --- /dev/null +++ b/.devcontainer/spike/compose.yaml @@ -0,0 +1,46 @@ +services: + certs-init: + image: ghcr.io/cmaneu/entra-local@sha256:70584ef110914d100409cb3d63a63548ccdde10ca780f9751755f1482dec5d7e + user: root + entrypoint: ["sh", "-ec"] + command: + - "cp /source/* /certs/; chown -R 1000:1000 /certs; chmod 755 /certs; chmod 644 /certs/*.pem; chmod 640 /certs/*-key.pem" + volumes: + - ${SPIKE_CERT_DIR:?required}:/source:ro + - certs:/certs + entra-local: + image: ghcr.io/cmaneu/entra-local@sha256:70584ef110914d100409cb3d63a63548ccdde10ca780f9751755f1482dec5d7e + environment: + PUBLIC_ORIGIN: ${PUBLIC_ORIGIN:?required} + ISSUER: ${ISSUER:?required} + TENANT_ID: ${AUTH_TENANT_ID:?required} + TLS_ENABLED: "true" + TLS_CERT: /certs/edge.pem + TLS_KEY: /certs/edge-key.pem + NODE_EXTRA_CA_CERTS: /certs/rootCA.pem + ports: + - "127.0.0.1:${SPIKE_ENTRA_PORT:?required}:8443" + volumes: + - data:/app/data + - certs:/certs:ro + depends_on: + certs-init: + condition: service_completed_successfully + healthcheck: + test: ["CMD", "node", "-e", "require('https').get('https://localhost:8443/health',r=>process.exit(r.statusCode===200?0:1)).on('error',()=>process.exit(1))"] + interval: 2s + timeout: 3s + retries: 30 + dev-edge: + image: nginx@sha256:5b4900b042ccfa8b0a73df622c3a60f2322faeb2be800cbee5aa7b44d241649e + network_mode: host + volumes: + - ${SPIKE_EDGE_CONFIG:?required}:/etc/nginx/conf.d/default.conf:ro + - certs:/certs:ro + - ${SPIKE_CERT_DIR:?required}/rootCA.pem:/ca/rootCA.pem:ro + depends_on: + entra-local: + condition: service_healthy +volumes: + data: + certs: \ No newline at end of file diff --git a/.dockerignore b/.dockerignore index cbcbab1dd..7739b7e50 100644 --- a/.dockerignore +++ b/.dockerignore @@ -31,6 +31,7 @@ ctrf # Local development TLS material is mounted at runtime, never built into images. .certs +.dev-state # Documentation (not needed in images) docs diff --git a/.github/workflows/devcontainer.yml b/.github/workflows/devcontainer.yml new file mode 100644 index 000000000..5be327a2a --- /dev/null +++ b/.github/workflows/devcontainer.yml @@ -0,0 +1,55 @@ +name: Devcontainer Contracts + +on: + pull_request: + paths: + - .devcontainer/** + - .vscode/launch.json + - scripts/dev/** + - package.json + - pnpm-lock.yaml + - .dockerignore + - .github/workflows/devcontainer.yml + push: + branches: [main] + paths: + - .devcontainer/** + - scripts/dev/** + - .github/workflows/devcontainer.yml + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: devcontainer-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + contracts: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '22.22.0' + - name: Install locked dependencies + run: | + corepack enable + corepack prepare pnpm@10.29.1 --activate + pnpm install --frozen-lockfile + - name: Test configuration and lifecycle contracts + run: pnpm exec vitest run scripts/dev + - name: Typecheck development tooling + run: pnpm exec tsc --noEmit --target ES2022 --module ESNext --moduleResolution Bundler --types node --esModuleInterop --skipLibCheck --strict scripts/dev/*.ts + - name: Validate shell and native infrastructure + env: + DEV_CERT_DIR: /tmp/scope-public-validation-certificates + run: | + bash -n .devcontainer/install-tools.sh + docker compose --file .devcontainer/native.compose.yaml config --quiet + - name: Check committed manifest generation + run: | + pnpm exec tsx scripts/dev/kind.ts .devcontainer/kind/base --defaults + git diff --exit-code -- .devcontainer/kind/base \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3f9b9adc2..5f3906e48 100644 --- a/.gitignore +++ b/.gitignore @@ -34,5 +34,8 @@ tmp/ # Local dev TLS certs (mkcert) for the entra-local auth emulator .certs/ +# Generated, workspace-scoped feasibility configuration and development CA +.dev-state/ + # NOTICE generation build cache (scripts/generate-notice.ts) .notice-build/ diff --git a/.vscode/launch.json b/.vscode/launch.json index b743138e2..b7cd1230b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,6 +1,61 @@ { "version": "0.2.0", "configurations": [ + { + "name": "Scope: Attach Native Node", + "type": "node", + "request": "attach", + "address": "127.0.0.1", + "port": "${input:scopeInspectorPort}", + "sourceMaps": true, + "restart": true, + "skipFiles": ["/**", "${workspaceFolder}/**/node_modules/**"] + }, + { + "name": "Scope: Attach Kind Node (Private Tunnel)", + "type": "node", + "request": "attach", + "address": "127.0.0.1", + "port": "${input:scopeInspectorPort}", + "localRoot": "${workspaceFolder}", + "remoteRoot": "/app", + "sourceMaps": true, + "restart": true, + "skipFiles": ["/**", "**/node_modules/**"] + }, + { + "name": "Scope: Gateway (Native Rust)", + "type": "lldb", + "request": "launch", + "cargo": { "args": ["build", "--locked", "--manifest-path", "${workspaceFolder}/apps/gateway/Cargo.toml"], "filter": { "name": "gateway", "kind": "bin" } }, + "cwd": "${workspaceFolder}/apps/gateway", + "args": ["--port", "18000", "--api-port", "18897"] + }, + { + "name": "Scope: Python (Workspace Environment)", + "type": "debugpy", + "request": "launch", + "python": "${workspaceFolder}/.venv/bin/python", + "program": "${file}", + "console": "integratedTerminal", + "justMyCode": true + }, + { + "name": "Scope: Portal (Desktop Chrome)", + "type": "pwa-chrome", + "request": "launch", + "url": "${input:scopeBrowserOrigin}", + "webRoot": "${workspaceFolder}/apps/portal", + "sourceMaps": true + }, + { + "name": "Scope: Portal (Desktop Edge)", + "type": "pwa-msedge", + "request": "launch", + "url": "${input:scopeBrowserOrigin}", + "webRoot": "${workspaceFolder}/apps/portal", + "sourceMaps": true + }, { "name": "Docker Dev Copilot", "type": "node", @@ -31,6 +86,19 @@ } ], "inputs": [ + { + "id": "scopeInspectorPort", + "type": "pickString", + "description": "Inspector started with pnpm dev:debug --service=", + "options": ["9230", "9231", "9232", "9233", "9240", "9241", "9242", "9243", "9250", "9251", "9252", "9253", "9254", "9260", "9261", "9262", "9263"], + "default": "9230" + }, + { + "id": "scopeBrowserOrigin", + "type": "promptString", + "description": "Current PUBLIC_ORIGIN reported by pnpm dev:doctor", + "default": "https://localhost:8443" + }, { "id": "apiDebugPort", "type": "promptString", diff --git a/AGENTS.md b/AGENTS.md index 11ddac8bd..fba2fbf0f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -276,6 +276,7 @@ not open the PR against the fork unless the user explicitly asks you to. | [docs/architecture/post-processing.md](docs/architecture/post-processing.md) | Post-processing pipeline, ATIF generation, handler extensibility | | [docs/architecture/observability.md](docs/architecture/observability.md) | Application telemetry, Azure Monitor OTel distro, custom worker metrics | | [docs/architecture/kubedock.md](docs/architecture/kubedock.md) | Kubedock sidecar, container access for agents, Kustomize Component toggle | +| [docs/architecture/devcontainer.md](docs/architecture/devcontainer.md) | Experimental DinD/Kind auth topology spike, evidence and remaining implementation gates | | [docs/research/realtime-data-flow.md](docs/research/realtime-data-flow.md) | SSE + Change Streams, Redis pub/sub, polling patterns | | [docs/research/delta-storage.md](docs/research/delta-storage.md) | Space-efficient storage of iteration snapshots | | [docs/shared-dev-infra.md](docs/shared-dev-infra.md) | Shared dev infrastructure (CosmosDB) setup and worktree isolation | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a90006f0f..4323a1d6d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,6 +58,18 @@ dependencies. ## Local development +### Experimental devcontainer spike + +The checked-in devcontainer currently provides only a phase-one DinD/Kind and +Entra/dev-edge feasibility probe, **not the full Scope stack**. It requires a +privileged, disposable outer container. See the +[spike instructions and evidence ledger](./docs/architecture/devcontainer.md) +before using `pnpm dev:spike doctor`. Real local-browser and private-Codespaces +login remain unverified; use the existing Compose workflow below for regular +development. Never transfer a development CA private key to the browser host. + +### Existing Compose workflow + Local authentication requires your browser to trust a development certificate. The Portal development scripts run `mkcert -install` to add a local certificate authority to the OS/browser trust store and generate the emulator's `localhost` diff --git a/ENV_VARIABLES.md b/ENV_VARIABLES.md index bc66a4316..85111817a 100644 --- a/ENV_VARIABLES.md +++ b/ENV_VARIABLES.md @@ -1020,11 +1020,20 @@ usually left unset. Every selected key must contain a non-empty string `issuer`; missing, malformed, ambiguous, or mismatched key issuer metadata rejects the token. -> **entra-local compatibility prerequisite.** At the time this validation was -> introduced, the external `cmaneu/entra-local` JWKS omitted the `issuer` -> extension. Auth-enabled local development therefore requires an emulator -> version that publishes the configured per-tenant issuer on every signing key. -> This Scope change does not modify the external emulator. +> **entra-local compatibility.** The 0.1.1 image at digest +> `sha256:70584ef110914d100409cb3d63a63548ccdde10ca780f9751755f1482dec5d7e` +> was probed with verified TLS and publishes the configured external issuer on +> every JWK. Earlier warnings about missing metadata do not establish that this +> image is incompatible. The [devcontainer spike](docs/architecture/devcontainer.md) +> records the limited evidence; browser PKCE and Portal/API login remain unverified. +> Do not remove key-issuer checks to accommodate an incompatible emulator. + +> **Experimental dev-edge inputs.** Only `pnpm dev:spike` consumes `PUBLIC_ORIGIN`, +> `EDGE_PORT` (Codespaces HTTP, 8080), `EDGE_TLS_PORT` (local HTTPS, 8443), and +> `SPIKE_ENTRA_PORT` (private loopback TLS, 18443). Codespaces origins are resolved +> from `CODESPACE_NAME` and `GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN` at runtime. +> Process environment overrides defaults; the spike does not read `.env.local` +> or generated `.env`. This is not yet a shared full-stack precedence contract. > **Local dev TLS.** Compose trusts the emulator's mkcert CA through a read-only > public-CA mount and `NODE_EXTRA_CA_CERTS`; the certificate covers the internal diff --git a/apps/model-scanners/anthropic/Dockerfile b/apps/model-scanners/anthropic/Dockerfile index 8293f780e..0880e864e 100644 --- a/apps/model-scanners/anthropic/Dockerfile +++ b/apps/model-scanners/anthropic/Dockerfile @@ -29,6 +29,9 @@ COPY apps/model-scanners/anthropic/src ./apps/model-scanners/anthropic/src/ RUN pnpm --filter shared build && pnpm --filter telemetry build && pnpm --filter model-scanning build && pnpm --filter model-scanner-anthropic build +FROM builder AS dev +CMD ["node", "--conditions=source", "--enable-source-maps", "--import", "tsx", "apps/model-scanners/anthropic/src/index.ts"] + # --- Production stage --- FROM node:22.22.0-slim diff --git a/apps/model-scanners/copilot/Dockerfile b/apps/model-scanners/copilot/Dockerfile index 9741a758e..eb837ebc7 100644 --- a/apps/model-scanners/copilot/Dockerfile +++ b/apps/model-scanners/copilot/Dockerfile @@ -29,6 +29,9 @@ COPY apps/model-scanners/copilot/src ./apps/model-scanners/copilot/src/ RUN pnpm --filter shared build && pnpm --filter telemetry build && pnpm --filter model-scanning build && pnpm --filter model-scanner-copilot build +FROM builder AS dev +CMD ["node", "--conditions=source", "--enable-source-maps", "--import", "tsx", "apps/model-scanners/copilot/src/index.ts"] + # --- Production stage --- FROM node:22.22.0-slim diff --git a/apps/portal/vite.config.ts b/apps/portal/vite.config.ts index 7d505e1ab..912b2aebb 100644 --- a/apps/portal/vite.config.ts +++ b/apps/portal/vite.config.ts @@ -28,6 +28,10 @@ function getGitInfo() { } const git = getGitInfo(); +const edgeOrigin = process.env.VITE_DEV_EDGE_ORIGIN ? new URL(process.env.VITE_DEV_EDGE_ORIGIN) : undefined; +if (edgeOrigin && (edgeOrigin.protocol !== "https:" || edgeOrigin.username || edgeOrigin.password || edgeOrigin.pathname !== "/" || edgeOrigin.search || edgeOrigin.hash)) { + throw new Error("VITE_DEV_EDGE_ORIGIN must be an exact HTTPS origin"); +} export default defineConfig({ plugins: [react()], @@ -43,6 +47,9 @@ export default defineConfig({ }, server: { port: 5100, + strictPort: edgeOrigin ? true : undefined, + allowedHosts: edgeOrigin ? [edgeOrigin.hostname] : undefined, + hmr: edgeOrigin ? { protocol: "wss", host: edgeOrigin.hostname, clientPort: Number(edgeOrigin.port || "443") } : undefined, proxy: { "/api": { target: process.env.VITE_API_PROXY_TARGET || "http://localhost:3100", diff --git a/docs/architecture/auth-rbac.md b/docs/architecture/auth-rbac.md index 12fb57c2c..8e88da02e 100644 --- a/docs/architecture/auth-rbac.md +++ b/docs/architecture/auth-rbac.md @@ -68,6 +68,13 @@ must be resolved with stakeholders before or during implementation. ## Current implementation +The experimental [DinD/Kind development spike](devcontainer.md) verifies Entra +Local 0.1.1's external discovery/JWK issuers through a private internal TLS +endpoint and dev-edge. It does not change this authentication boundary or prove +browser PKCE, API enrollment, cached reload, logout, or Codespaces forwarding. +Those remain explicit phase-one acceptance gates; no synthetic principal or +verification bypass is introduced. + | Component | In this branch | Relevant files | |-----------|-------|----------------| | API | Verifies the IdP signature and claims before any access-cache lookup. `/users/me` owns explicit enrollment; subsequent middleware resolves existing active users. Public/anonymous rollout is unchanged. | [apps/api/src/index.ts](../../apps/api/src/index.ts), [auth/middleware.ts](../../apps/api/src/auth/middleware.ts), [routes/users.ts](../../apps/api/src/routes/users.ts) | diff --git a/docs/architecture/devcontainer.md b/docs/architecture/devcontainer.md new file mode 100644 index 000000000..14b384791 --- /dev/null +++ b/docs/architecture/devcontainer.md @@ -0,0 +1,204 @@ +# Devcontainer and Kind feasibility spike + +Status: **phase one is incomplete; phases two through six have not started**. +The checked-in devcontainer is an experimental topology/auth probe, not a +complete Scope development environment. The broader implementation remains gated +on real local-browser and owner-private Codespaces PKCE login, including the +Portal/API handshake. Source inspection and localhost HTTP probes are not that +evidence. Existing Compose, worktree offsets, and k3d commands are unchanged. + +## Prerequisites and isolation + +The maintained Docker-in-Docker feature requires a **privileged outer container**. +The editor uses its own Docker daemon and persistent, devcontainer-scoped Docker +and containerd volumes, not a mounted host socket. This is **not a security +sandbox** for untrusted benchmark tasks. Use a disposable machine without +sensitive host mounts. Worker task toolchains still belong in worker images. + +The spike uses Node 22.22.0, pnpm from the root `packageManager`, Kind 0.27.0, +kubectl 1.32.2, Compose 2.35.1, Buildx 0.22.0, Docker Engine 29.3.0, and the locked +DinD 4.1.3 feature. Release binaries use published checksums. Base/emulator/edge +and Kind node images are digest-pinned. Debian packages are **not snapshot-pinned**; +this is not the final reproducible toolchain. Node 24 selection, Rust, Python/uv, +browsers, Azure/PowerShell, and the remaining phase-two tools are still pending. + +Initial sizing **targets, not verified minimums**: 4 CPUs / 16 GB for fast mode; +8 CPUs / 32 GB and at least 80 GB available disk for full Kind. On Docker Desktop, +configure the same CPU/RAM allocations and sufficient disk capacity under +Settings -> Resources (or the WSL2 resource configuration on Windows). The spike +bounds Compose concurrency at two; it does not start any workers. Full-stack +build and worker concurrency limits and cold/steady-state measurements remain +required. arm64 and Windows/macOS have not been validated; do not assume that +all images run natively on arm64. Windows worker execution and image validation +remain separate Windows targets, not Linux/Kind capabilities. + +## Run the probe + +Reopen the workspace in its devcontainer. Creation installs only locked root +dependencies. Attach prints guidance; it does not enroll users, migrate data, +run providers, restore a mode, or start watchers. The complete create/start/ +attach lifecycle is phase-two work. No secrets or forwarding URLs are image +inputs. The experimental pnpm cache is devcontainer-scoped; do not reuse these +volumes between CPU architectures. + +```bash +pnpm dev:spike doctor +pnpm dev:spike config +pnpm dev:spike up +pnpm dev:spike probe +pnpm dev:spike logs +pnpm dev:spike down +``` + +`doctor` reports tools, daemon availability, resources, and whether provider +credential variables are present, never their values. Presence does not prove +entitlement. It does not yet implement the complete resource/port/provider +acceptance checks. `config` generates ignored non-secret files under +`.dev-state/spike`. This spike uses **process environment > built-in defaults**; +it deliberately does not read or modify `.env.local` or worktree-generated +`.env`. A shared native/Compose/Kind precedence resolver is still required. + +Inputs: `PUBLIC_ORIGIN`, `AUTH_TENANT_ID` (UUID), `EDGE_PORT` (Codespaces, +default 8080), `EDGE_TLS_PORT` (local, default 8443), and `SPIKE_ENTRA_PORT` +(internal loopback TLS, default 18443). Non-default local ports must be forwarded +unchanged. Stop, regenerate settings, and restart edge **and Vite** when the origin +changes. Startup rejects stale generated edge settings and occupied ports. + +Codespaces resolves `https://${CODESPACE_NAME}-${EDGE_PORT}.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}` +at runtime, or uses an explicit `PUBLIC_ORIGIN` override for another remote +environment. Local origin defaults to `https://localhost:${EDGE_TLS_PORT}`. +Neither request `Host` nor forwarded headers establish trusted issuer settings. + +Only forward the selected edge port. In Codespaces, keep it **private to its +owner**, with forwarding protocol **HTTP**, even though the external URL is +HTTPS. The configuration disables automatic forwarding. Authenticate to the +forwarded application with a top-level browser navigation. Never make Entra's +port public or inject a repository token into the browser. External REST clients +need forwarding-layer authentication separately from their unchanged IdP bearer; +internal CLI/API/JWKS requests must bypass that layer. + +The probe starts **only Entra Local and dev-edge**, plus certificate staging. +It registers the exact current origin on the seeded SPA app via the loopback +admin endpoint. Only 201/already-present 409 succeed; bounded transient retries +and five-second request timeouts apply. It checks discovery URLs, every JWK's +external issuer, nginx discovery proxying, and denied admin/unknown-auth routes. +It does not perform interactive enrollment, logout, or model calls. + +The edge runs in the editor network namespace, with native upstream slots +`localhost:3100` (API) and `localhost:5100` (Vite). **Those applications and their +infrastructure are not provisioned by this spike.** Portal/API routes return +502 until the applications run; this is not a usable full-stack browser URL yet. +API and auth routes precede SPA fallback; streaming and WebSocket upgrades are +configured. Full HMR/upload/download/SSE/artifact verification remains pending. + +The generated `public.json` records external issuer/authority/redirect settings +and the native JWKS URL. It contains no credentials. It is not automatically +loaded into API/Vite. Compose and Kind settings must later use their own private +DNS JWKS addresses while preserving the external issuer and unchanged bearer +validation, including selected-key issuer checks. Exact Vite allowed hosts and +Codespaces `wss`/443 HMR configuration remain integration work. + +## TLS and state + +mkcert generates the CA in `.dev-state/spike/authority`, outside mounted leaf +certificates. **Never transfer `rootCA-key.pem`**. Only leaf certificates/keys and +the public `rootCA.pem` enter the certificate volume; clients receive public CA +material. The nginx, Node, and curl probes keep TLS verification enabled. +Generated state and certificates are excluded from image build contexts. + +For a real local-host browser test, copy **only** +`.dev-state/spike/certs/rootCA.pem` to the host and import it into that host's +trusted root certificate store (and Firefox's store if separate). On Linux, +use the distribution's public-root installation procedure; macOS uses the System +Keychain; Windows uses Trusted Root Certification Authorities. Container-side +`mkcert -install` cannot establish host-browser trust. Remove the public root +from the host when retiring the environment. Codespaces browsers instead trust +GitHub's external certificate. Lowkey Vault trust is not configured in this spike; +its later integration must not reuse a TLS-verification bypass. + +Normal `down`, container stop, and rebuild preserve emulator data in the scoped +Docker volume. CA files remain in the ignored workspace directory. Back up these +separately before deleting the workspace or outer Docker volumes. Destructive +reset requires the exact project name printed by `doctor`: + +```bash +pnpm dev:spike reset-data --confirm=scope-spike- +``` + +This deletes only that Compose project's emulator/certificate volumes, including +registrations and signing keys, not other projects or the CA directory. It does +not remove a Kind cluster. Failed startup leaves state for diagnosis; use `logs` +and `down`, not global Docker prune/reset commands. + +## Kind boot only + +Stop the auth spike first; its Codespaces listener and Kind mapping both use +8080. The optional boot probe has no application manifests, PVCs or workers. + +```bash +pnpm dev:spike kind-up +pnpm dev:spike kind-down +``` + +The single node maps NodePort 30080 to loopback 8080. No Service is installed by +the spike. Every client operation names the cluster context and +`.dev-state/spike/kubeconfig`; the default kubeconfig is untouched and the API +is never browser-forwarded. Kind deletion removes only this named cluster. +Persistent workload storage, ServiceAccounts/RBAC, Kubedock, and the full local +Kustomize stack remain phase-four work. No privileged kubeconfig or Docker/runtime +socket is mounted into application pods; none are deployed yet. + +## Runtime inventory and remaining sequence + +This is the reviewed coverage checklist for the later implementation, not a +claim that every target currently exists. + +| Category | Required targets | Spike coverage | +| --- | --- | --- | +| Backing services | Replica-set MongoDB, Redis, all Azurite APIs, Lowkey Vault, Entra Local | Entra only | +| Initialization | Certificates, replica set, migrations, blobs/queues, redirects, agents/versions | Certificates and exact redirects only | +| Applications | API, Portal, Judge, token-manager, scheduler, Rust gateway | Edge upstream slots only | +| Workers | Copilot, Claude Code, report-generator, post-processor; existing enabled proxy/MCP sidecars | None; do not start paid workloads | +| Utilities | Copilot/Anthropic scanners, checked-in version checkers, cookie updater | None; explicit commands/jobs required | +| Developer tools | CLI, migrations, Vitest, Storybook, prompt evals, separate Astro install, Python environment | Focused Vitest tests only | +| Libraries | Workspace dependencies built/watched in dependency order | Not provisioned | +| Windows | Separate image/runtime, private tunnel, `C:/app` mapping, Windows CI | Existing Windows exception preserved | + +After the real login gate: phase two supplies the full pinned toolchain and +lifecycle; phase three supplies replica-set infrastructure, native launch tasks, +container workers and host-gateway routes; phase four supplies all images, +Kustomize/Jobs, persisted Kind state and least-privilege identities/Kubedock; +phase five supplies runtime-wide debugging, supervised private tunnels and +validated Skaffold sync/rebuild; phase six supplies credential-free CI smoke, +opt-in trusted provider tests and the complete acceptance matrix. Proposed +`dev:doctor`, `dev:up --mode=...`, `dev:down`, and `dev:debug` commands are **not +implemented**; do not confuse them with `dev:spike`. + +## Evidence ledger + +Observed on 2026-11-02, Linux amd64 Codespaces host, 8 CPUs, 31.3 GiB RAM, +49 GiB initially free disk (below the full-Kind target): + +| Check | Result | +| --- | --- | +| Origin, routing, retries, workspace names and metadata unit tests | 58 passed | +| Base spike image and maintained DinD feature | Built; privileged container started with CLI 0.90.0 | +| Dockerfile checks / isolated Compose configuration | Passed | +| DinD Entra + nginx HTTP and HTTPS probes | Passed with verified internal CA | +| Redirect repeated probe and stop/start | Passed without removing data volumes | +| Wrong-host TLS certificate | Rejected by curl with exit 60 | +| Kind internal `/readyz` with scoped kubeconfig | Passed; node readiness reported 17 seconds, not total cold-start time | +| Idle auth-only snapshot | Entra 51.15 MiB / 9.90% CPU; edge 8.434 MiB / 0.00% CPU; not a sustained/full-stack measurement | +| Real PKCE/refresh/logout, Portal POST enrollment/GET reload, invalid-token tests | **Not run; phase-one exit gate remains open** | +| Private forwarding, host-browser trust, HMR/SSE/downloads, full-stack/provider/debugger/RBAC/platform acceptance | **Not run** | + +Immutable references used: + +- Node 22.22.0 bookworm: `sha256:20a424ecd1d2064a44e12fe287bf3dae443aab31dc5e0c0cb6c74bef9c78911c` +- Entra Local 0.1.1: `sha256:70584ef110914d100409cb3d63a63548ccdde10ca780f9751755f1482dec5d7e` +- nginx 1.28.2 alpine: `sha256:5b4900b042ccfa8b0a73df622c3a60f2322faeb2be800cbee5aa7b44d241649e` +- Kind node 1.32.2: `sha256:142f543559cc55d64e1ab9341df08e5ced84bd2e893736da8f51320f26f5950b` +- DinD 4.1.3: feature digest/integrity in `.devcontainer/devcontainer-lock.json`. + +No live-provider entitlement, cold full-stack build, sustained resource load, +debugger breakpoint, arm64, Docker Desktop, or Windows success is implied. \ No newline at end of file diff --git a/docs/architecture/kubedock.md b/docs/architecture/kubedock.md index 80d7fa932..e4e6ba095 100644 --- a/docs/architecture/kubedock.md +++ b/docs/architecture/kubedock.md @@ -38,6 +38,12 @@ Kubedock gives coding agents the ability to run Docker commands (build, run, exe ## Feature Flag (Kustomize Component) +The component described below is a design contract, not a component supplied by +the experimental [Kind boot spike](devcontainer.md). That spike deploys no +workers or Kubedock resources. A self-contained local component, scoped RBAC, +projected tokens and representative Docker-operation tests are still required +before claiming Kind worker support. + Kubedock is deployed as a **Kustomize Component** that overlays opt into per environment. ### Enabling in an environment diff --git a/package.json b/package.json index 635bb66ae..ee1abaf2e 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,19 @@ "build:cli": "pnpm --filter shared build && pnpm --filter cli build", "dev:api": "pnpm --filter api dev", "dev:portal": "pnpm --filter portal dev", + "dev:spike": "tsx scripts/dev/spike.ts", + "dev:doctor": "tsx scripts/dev/control.ts doctor", + "dev:config": "tsx scripts/dev/control.ts config", + "dev:up": "tsx scripts/dev/control.ts up", + "dev:down": "tsx scripts/dev/control.ts down", + "dev:logs": "tsx scripts/dev/control.ts logs", + "dev:reset-data": "tsx scripts/dev/control.ts reset-data", + "dev:run": "tsx scripts/dev/control.ts run", + "dev:debug": "tsx scripts/dev/control.ts run --debug", + "dev:images": "tsx scripts/dev/control.ts images", + "dev:job": "tsx scripts/dev/control.ts job", + "dev:workers": "tsx scripts/dev/control.ts workers", + "dev:smoke": "tsx scripts/dev/acceptance.ts", "shared-infra:setup": "scripts/shared-infra-setup.sh", "shared-infra:use": "scripts/shared-infra-use.sh", "shared-infra:use:off": "scripts/shared-infra-use.sh --off", diff --git a/scripts/dev/acceptance.ts b/scripts/dev/acceptance.ts new file mode 100644 index 000000000..0a489ccf6 --- /dev/null +++ b/scripts/dev/acceptance.ts @@ -0,0 +1,53 @@ +import { existsSync, readFileSync } from "node:fs"; +import { request } from "node:https"; +import { resolve } from "node:path"; +import { resolveDevConfig } from "./config.js"; +import { execute, loadInputs, root, stateDirectory } from "./control.js"; + +async function check(url: URL, ca: Buffer, bearer?: string): Promise<{ status: number; body: string }> { + if (url.protocol === "http:") { + const response = await fetch(url, { headers: bearer ? { authorization: `Bearer ${bearer}` } : {}, signal: AbortSignal.timeout(10_000) }); + return { status: response.status, body: await response.text() }; + } + return new Promise((resolvePromise, reject) => { + const req = request(url, { ca, headers: bearer ? { authorization: `Bearer ${bearer}` } : {}, timeout: 10_000 }, (response) => { + let body = ""; + response.setEncoding("utf8"); + response.on("data", (chunk: string) => { body += chunk; }); + response.on("error", reject); + response.on("end", () => resolvePromise({ status: response.statusCode || 0, body })); + }); + req.on("error", reject); + req.on("timeout", () => req.destroy(new Error("Smoke request timed out"))); + req.end(); + }); +} + +async function main(): Promise { + const mode = process.argv.find((argument) => argument.startsWith("--mode="))?.slice(7) || "native"; + if (mode !== "native" && mode !== "kind") throw new Error("Smoke mode must be native or kind"); + const statePath = resolve(stateDirectory, "mode.json"); + if (existsSync(statePath)) { + const state: { active?: boolean } = JSON.parse(readFileSync(statePath, "utf8")); + if (state.active) throw new Error("Run dev:down before smoke testing; active development resources will not be taken over"); + } + const inputs = loadInputs(); + const config = resolveDevConfig({ ...inputs.generated, ...inputs.local, ...inputs.process }); + const origin = new URL(`${config.codespaces ? "http" : "https"}://localhost:${config.edgePort}`); + const started = Date.now(); + try { + execute("pnpm", ["dev:up", `--mode=${mode}`, "--services=api,portal", ...(process.argv.includes("--build") ? ["--build"] : [])], process.env, root, 0); + const ca = readFileSync(resolve(root, ".dev-state/spike/certs/rootCA.pem")); + for (const path of ["/health", "/ready", "/"]) { + const response = await check(new URL(path, origin), ca); + if (response.status !== 200 || (path === "/" && !response.body.includes(" { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1; }); \ No newline at end of file diff --git a/scripts/dev/bootstrap.ts b/scripts/dev/bootstrap.ts new file mode 100644 index 000000000..0fdf02b2e --- /dev/null +++ b/scripts/dev/bootstrap.ts @@ -0,0 +1,91 @@ +import { execFileSync } from "node:child_process"; +import { readFileSync } from "node:fs"; +import { createRequire } from "node:module"; +import { request } from "node:https"; +import { resolve } from "node:path"; +import { setTimeout as delay } from "node:timers/promises"; +import { fileURLToPath } from "node:url"; +import { registerRedirect, verifyMetadata } from "./spike.js"; +import { DEFAULT_TENANT, SPA_CLIENT_ID } from "./config.js"; + +const root = resolve(fileURLToPath(new URL("../..", import.meta.url))); +const shared = createRequire(resolve(root, "packages/shared/package.json")); + +/** Use one capped retry layer for idempotent emulator bootstrap operations. */ +export async function retry(operation: () => Promise, attempts = 30): Promise { + for (let attempt = 0; ; attempt++) { + try { return await operation(); } + catch (error) { + if (attempt + 1 >= attempts || (error instanceof Error && error.message.startsWith("Permanent HTTP"))) throw error; + await delay(Math.min(250 * 2 ** attempt, 2000)); + } + } +} + +async function postJson(path: string, body: unknown): Promise { + await retry(async () => { + const response = await fetch(`${process.env.API_ENDPOINT || "http://api:80"}${path}`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body), signal: AbortSignal.timeout(10_000) }); + if (!response.ok) throw new Error(`${response.status < 500 && response.status !== 429 ? "Permanent HTTP" : "HTTP"} ${response.status} for ${path}`); + }); +} + +export async function bootstrap(command: string): Promise { + if (command === "storage-init") { + type StorageOptions = { retryOptions: { maxTries: number; tryTimeoutInMs: number } }; + const { BlobServiceClient } = shared("@azure/storage-blob") as { BlobServiceClient: { fromConnectionString(connection: string, options: StorageOptions): { getContainerClient(name: string): { createIfNotExists(): Promise } } } }; + const { QueueServiceClient } = shared("@azure/storage-queue") as { QueueServiceClient: { fromConnectionString(connection: string, options: StorageOptions): { getQueueClient(name: string): { createIfNotExists(): Promise } } } }; + const connection = process.env.STORAGE_CONNECTION_STRING; + if (!connection) throw new Error("STORAGE_CONNECTION_STRING is required"); + const options = { retryOptions: { maxTries: 1, tryTimeoutInMs: 10_000 } }; + const blobs = BlobServiceClient.fromConnectionString(connection, options); + const queues = QueueServiceClient.fromConnectionString(connection, options); + for (const name of ["har", "logs", "snapshots", "task-prompts", "skills", "codebases", "resources"]) await retry(() => blobs.getContainerClient(name).createIfNotExists()); + for (const name of ["queue-coder-acp-copilot", "queue-coder-acp-claude-code", "report-queue", "post-processor-queue"]) await retry(() => queues.getQueueClient(name).createIfNotExists()); + return; + } + if (command === "db-migrate") { + execFileSync("pnpm", ["--filter", "db-migrations", "migrate:up"], { cwd: root, stdio: "inherit", timeout: 300_000 }); + return; + } + if (command === "register-agents") { + const { parse } = shared("yaml") as { parse(source: string): unknown }; + for (const name of ["coder-acp-copilot", "coder-acp-claude-code"]) { + const directory = resolve(root, "apps/workers", name); + const agent: unknown = parse(readFileSync(resolve(directory, "agent.yaml"), "utf8")); + if (!agent || typeof agent !== "object") throw new Error(`Invalid agent manifest ${name}`); + await postJson("/api/v1/agents", { ...agent, available: false }); + const version: unknown = parse(readFileSync(resolve(directory, "agent-version.dev.yaml"), "utf8")); + await postJson(`/api/v1/agents/${name}/versions`, version); + } + return; + } + if (command === "redirect-init") { + const origin = process.env.PUBLIC_ORIGIN; + if (!origin) throw new Error("PUBLIC_ORIGIN is required"); + const tenant = process.env.AUTH_TENANT_ID || DEFAULT_TENANT; + const ca = readFileSync(process.env.NODE_EXTRA_CA_CERTS || "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/ca/rootCA.pem"); + const internal = process.env.ENTRA_INTERNAL_ORIGIN || "https://entra-local:8443"; + const send = (path: string, body?: string): Promise<{ status: number; body: unknown }> => new Promise((resolvePromise, reject) => { + const req = request(`${internal}${path}`, { ca, method: body ? "POST" : "GET", headers: { "content-type": "application/json" }, timeout: 5000 }, (response) => { + let text = ""; + response.setEncoding("utf8"); + response.on("data", (chunk: string) => { text += chunk; }); + response.on("error", reject); + response.on("end", () => { try { const body: unknown = JSON.parse(text); resolvePromise({ status: response.statusCode || 0, body }); } catch (error) { reject(error); } }); + }); + req.on("error", reject); + req.on("timeout", () => req.destroy(new Error("Entra bootstrap timed out"))); + req.end(body); + }); + await registerRedirect(() => send(`/admin/api/apps/${SPA_CLIENT_ID}/redirectUris`, JSON.stringify({ uri: origin, type: "spa" }))); + const discovery = await retry(() => send(`/${tenant}/v2.0/.well-known/openid-configuration`)); + const keys = await retry(() => send(`/${tenant}/discovery/v2.0/keys`)); + verifyMetadata(discovery.body, keys.body, origin, tenant); + return; + } + throw new Error(`Unknown initialization target: ${command}`); +} + +if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { + bootstrap(process.argv[2]).catch((error: unknown) => { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1; }); +} \ No newline at end of file diff --git a/scripts/dev/cluster.ts b/scripts/dev/cluster.ts new file mode 100644 index 000000000..74f1fd781 --- /dev/null +++ b/scripts/dev/cluster.ts @@ -0,0 +1,143 @@ +import { execFileSync, spawn } from "node:child_process"; +import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; +import { resolve } from "node:path"; +import { parseEnv } from "node:util"; +import { setTimeout as delay } from "node:timers/promises"; +import { resolveDevConfig } from "./config.js"; +import { execute, project, root, stateDirectory } from "./control.js"; +import { renderKindStack, namespace } from "./kind.js"; +import { runtimes, runtimeByName } from "./inventory.js"; + +export const kubeconfig = resolve(stateDirectory, "kubeconfig"); +export const context = `kind-${project}`; + +export function kubectl(args: string[], env = process.env): void { + execute("kubectl", ["--kubeconfig", kubeconfig, "--context", context, "--namespace", namespace, ...args], env); +} + +export function inspectorCommand(command: string[], port: number): string[] { + if (command[0] !== "node" || !Number.isInteger(port) || port < 1024 || port > 65535) throw new Error("A Node entrypoint and valid inspector port are required"); + return ["node", `--inspect-brk=0.0.0.0:${port}`, ...command.slice(1).filter((argument) => argument !== "--watch" && !argument.startsWith("--inspect"))]; +} + +/** Forward only loopback, retry replaced service pods, and never rerun a completed utility. */ +export async function debugRuntime(env: NodeJS.ProcessEnv, name: string, args: string[] = []): Promise { + const entry = runtimeByName(name); + if (!entry.inspector) throw new Error(`${name} has no Node inspector; use its dedicated debugger profile`); + const resource = renderKindStack({ ...env, SCOPE_IMAGE_TAG: project }).find((item) => (item.kind === "Deployment" || item.kind === "Job") && (item.metadata as { name: string }).name === name); + if (!resource) throw new Error(`Missing workload ${name}`); + const workload = resource.kind === "Job" ? "job" : "deployment"; + type Container = { name: string; command: string[]; startupProbe?: unknown; readinessProbe?: unknown }; + const spec = resource.spec as { suspend?: boolean; template: { spec: { containers: Container[] } } }; + const container = spec.template.spec.containers[0]; + const command = inspectorCommand([...container.command, ...args], entry.inspector); + if (resource.kind === "Job") { + kubectl(["delete", "job", name, "--ignore-not-found", "--wait=true", "--timeout=60s"], env); + container.command = command; + spec.suspend = false; + applyObject(resource); + } else { + kubectl(["patch", "deployment", name, "--type=strategic", "-p", JSON.stringify({ spec: { replicas: 1, template: { spec: { containers: [{ name, command, startupProbe: null, readinessProbe: null }] } } } })], env); + } + let stopping = false; + let child: ReturnType | undefined; + const stop = (): void => { stopping = true; child?.kill("SIGTERM"); }; + process.once("SIGINT", stop); + process.once("SIGTERM", stop); + console.log(`Attach ${name} at 127.0.0.1:${entry.inspector}; source root /app. No inspector Service or browser forwarding is created.`); + try { + while (!stopping) { + child = spawn("kubectl", ["--kubeconfig", kubeconfig, "--context", context, "--namespace", namespace, "port-forward", "--address=127.0.0.1", `${workload}/${name}`, `${entry.inspector}:${entry.inspector}`, "--pod-running-timeout=90s"], { env, stdio: "inherit" }); + await new Promise((resolvePromise, reject) => { child!.once("exit", () => resolvePromise()); child!.once("error", reject); }); + if (resource.kind === "Job") break; + if (!stopping) await delay(1000); + } + } finally { + process.removeListener("SIGINT", stop); + process.removeListener("SIGTERM", stop); + child?.kill("SIGTERM"); + if (resource.kind === "Deployment") kubectl(["patch", "deployment", name, "--type=strategic", "-p", JSON.stringify({ spec: { template: { spec: { containers: [{ name, command: container.command, startupProbe: container.startupProbe ?? null, readinessProbe: container.readinessProbe ?? null }] } } } })], env); + } +} + +/** Build serially to bound peak disk/RAM; images never require a registry. */ +export function buildImages(env: NodeJS.ProcessEnv, selected: string[]): void { + for (const name of new Set(selected)) { + const entry = name === "tools" ? undefined : runtimeByName(name); + const tools = !entry?.dockerfile; + const imageName = tools ? "tools" : name; + const dockerfile = tools ? ".devcontainer/runtime.Dockerfile" : entry.dockerfile!; + const args = ["build", "--file", resolve(root, dockerfile), "--tag", `scope-local/${imageName}:${project}`]; + if (entry?.kind === "rust") args.push("--target", "runtime"); + else if (!tools) args.push("--target", "dev"); + const versions = entry ? resolve(root, entry.directory, "versions.env") : ""; + if (versions && existsSync(versions)) for (const [key, value] of Object.entries(parseEnv(readFileSync(versions, "utf8")))) args.push("--build-arg", `${key}=${value}`); + execute("docker", [...args, entry?.kind === "rust" ? resolve(root, entry.directory) : root], env, root, 0); + execute("kind", ["load", "docker-image", "--name", project, `scope-local/${imageName}:${project}`], env, root, 0); + } +} + +function applyObject(value: unknown): void { + execFileSync("kubectl", ["--kubeconfig", kubeconfig, "--context", context, "--namespace", namespace, "apply", "-f", "-"], { input: JSON.stringify(value), stdio: ["pipe", "inherit", "inherit"], timeout: 60_000 }); +} + +/** Install runtime certificates only after startup, never in generated public manifests. */ +function uploadCertificates(): void { + const certificates: Record = {}; + for (const name of ["edge.pem", "edge-key.pem"]) certificates[name] = readFileSync(resolve(root, ".dev-state/spike/certs", name)).toString("base64"); + certificates["lowkey.p12"] = readFileSync(resolve(stateDirectory, "certs/lowkey.p12")).toString("base64"); + applyObject({ apiVersion: "v1", kind: "Secret", metadata: { name: "development-certificates", namespace }, type: "Opaque", data: certificates }); + const ca = readFileSync(resolve(root, ".dev-state/spike/certs/rootCA.pem"), "utf8") + readFileSync(resolve(stateDirectory, "certs/lowkey-ca.pem"), "utf8"); + applyObject({ apiVersion: "v1", kind: "ConfigMap", metadata: { name: "public-ca", namespace }, data: { "rootCA.pem": ca } }); +} + +export function startCluster(env: NodeJS.ProcessEnv, selected: string[], build = false): void { + const config = resolveDevConfig(env); + const persistent = resolve(env.SCOPE_DEV_DATA || resolve(root, ".dev-state/persistent")); + mkdirSync(persistent, { recursive: true }); + mkdirSync(stateDirectory, { recursive: true }); + const clusterFile = resolve(stateDirectory, "cluster.json"); + const node = "kindest/node:v1.32.2@sha256:142f543559cc55d64e1ab9341df08e5ced84bd2e893736da8f51320f26f5950b"; + writeFileSync(clusterFile, JSON.stringify({ kind: "Cluster", apiVersion: "kind.x-k8s.io/v1alpha4", networking: { apiServerAddress: "127.0.0.1" }, nodes: [{ role: "control-plane", image: node, extraMounts: [{ hostPath: persistent, containerPath: "/scope-state" }], extraPortMappings: [{ containerPort: 30080, hostPort: config.edgePort, listenAddress: "127.0.0.1", protocol: "TCP" }] }] }, null, 2)); + const names = execFileSync("kind", ["get", "clusters"], { encoding: "utf8", timeout: 30_000 }).split("\n"); + if (!names.includes(project)) execute("kind", ["create", "cluster", "--name", project, "--kubeconfig", kubeconfig, "--config", clusterFile, "--wait", "180s"], env); + else execute("kind", ["export", "kubeconfig", "--name", project, "--kubeconfig", kubeconfig], env); + const images = [...new Set(["tools", ...selected.map((name) => runtimeByName(name)).filter((entry) => entry.dockerfile).map((entry) => entry.name)])]; + if (build) buildImages(env, images); + else for (const name of images) execute("kind", ["load", "docker-image", "--name", project, `scope-local/${name}:${project}`], env); + const resources = renderKindStack({ ...env, SCOPE_IMAGE_TAG: project }); + for (const resource of resources) { + if (resource.kind === "Deployment") { + const metadata = resource.metadata as { name: string }; + if (runtimes.some((entry) => entry.name === metadata.name)) (resource.spec as Record).replicas = 0; + } + } + const directory = resolve(stateDirectory, "kustomize"); + mkdirSync(directory, { recursive: true }); + writeFileSync(resolve(directory, "resources.json"), JSON.stringify({ apiVersion: "v1", kind: "List", items: resources }, null, 2)); + writeFileSync(resolve(directory, "kustomization.yaml"), "apiVersion: kustomize.config.k8s.io/v1beta1\nkind: Kustomization\nresources:\n - resources.json\n" + (env.SCOPE_DEV_KUBEDOCK === "true" ? "components:\n - ../../../.devcontainer/kind/components/kubedock\n" : "")); + applyObject({ apiVersion: "v1", kind: "Namespace", metadata: { name: namespace } }); + uploadCertificates(); + for (const name of ["mongo-init", "storage-init", "redirect-init", "db-migrate", "register-agents"]) { + kubectl(["delete", "job", name, "--ignore-not-found", "--wait=true", "--timeout=60s"], env); + } + kubectl(["apply", "-k", directory], env); + for (const name of ["mongodb", "redis", "azurite", "entra-local", "lowkey-vault"]) kubectl(["rollout", "status", `deployment/${name}`, "--timeout=180s"], env); + kubectl(["patch", "job", "mongo-init", "--type=merge", "-p", '{"spec":{"suspend":false}}'], env); + kubectl(["wait", "--for=condition=complete", "job/mongo-init", "--timeout=180s"], env); + for (const name of ["storage-init", "redirect-init", "db-migrate"]) { + kubectl(["patch", "job", name, "--type=merge", "-p", '{"spec":{"suspend":false}}'], env); + kubectl(["wait", "--for=condition=complete", `job/${name}`, "--timeout=600s"], env); + } + for (const name of selected) { + const entry = runtimeByName(name); + if (entry.kind === "tool" || entry.kind === "utility") throw new Error(`${name} is a Job; launch it explicitly with dev:job`); + kubectl(["scale", `deployment/${name}`, "--replicas=1"], env); + kubectl(["rollout", "status", `deployment/${name}`, "--timeout=300s"], env); + } + if (selected.includes("api")) { + kubectl(["patch", "job", "register-agents", "--type=merge", "-p", '{"spec":{"suspend":false}}'], env); + kubectl(["wait", "--for=condition=complete", "job/register-agents", "--timeout=180s"], env); + } + console.log(`Kind ready. Browser: ${config.publicOrigin}`); +} \ No newline at end of file diff --git a/scripts/dev/config.test.ts b/scripts/dev/config.test.ts new file mode 100644 index 000000000..aeb92d8b8 --- /dev/null +++ b/scripts/dev/config.test.ts @@ -0,0 +1,79 @@ +import { describe, expect, it } from "vitest"; +import { DEFAULT_TENANT, renderEdgeRoutes, resolveDevConfig } from "./config.js"; + +describe("development origin contract", () => { + it("resolves local TLS and preserves the external port in known authorities", () => { + const config = resolveDevConfig({}); + expect(config.publicOrigin).toBe("https://localhost:8443"); + expect(config.auth.VITE_AUTH_KNOWN_AUTHORITIES).toBe("localhost:8443"); + expect(config.auth.AUTH_JWKS_URI).toBe(`https://entra-local:8443/${DEFAULT_TENANT}/discovery/v2.0/keys`); + expect(config.auth.AUTH_ISSUER_TEMPLATE).toBe("https://localhost:8443/{tenantid}/v2.0"); + }); + + it("computes the current Codespaces URL without a baked-in name", () => { + const config = resolveDevConfig({ CODESPACES: "true", CODESPACE_NAME: "example-123", GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN: "app.github.dev" }); + expect(config.publicOrigin).toBe("https://example-123-8080.app.github.dev"); + expect(config.edgePort).toBe(8080); + expect(config.auth.ISSUER).toBe(`${config.publicOrigin}/${DEFAULT_TENANT}/v2.0`); + }); + + it("accepts an explicit remote origin and local parallel-container port", () => { + expect(resolveDevConfig({ PUBLIC_ORIGIN: "https://dev.example.org" }).publicOrigin).toBe("https://dev.example.org"); + expect(resolveDevConfig({ EDGE_TLS_PORT: "9443" }).publicOrigin).toBe("https://localhost:9443"); + }); + + it.each(["http://localhost:8443", "https://user:password@localhost:8443", "https://localhost:8443/path", "https://localhost:8443?query", "https://localhost:8443#fragment", "https://127.0.0.1:8443", "https://localhost:9443", "https://bad;name.example"]) ("rejects unsafe or mismatched origin %s", (origin) => { + expect(() => resolveDevConfig({ PUBLIC_ORIGIN: origin })).toThrow(); + }); + + it.each(["0", "443", "65536", "8080junk", "8e3"]) ("rejects invalid edge port %s", (port) => { + expect(() => resolveDevConfig({ EDGE_TLS_PORT: port })).toThrow(); + }); + + it("fails on missing Codespaces inputs and unsafe tenant interpolation", () => { + expect(() => resolveDevConfig({ CODESPACES: "true" })).toThrow(/Codespaces/); + expect(() => resolveDevConfig({ AUTH_TENANT_ID: "../admin" })).toThrow(/UUID/); + }); +}); + +describe("dev-edge routing", () => { + const config = resolveDevConfig({}); + const routes = renderEdgeRoutes(config, { api: "http://api:3000", portal: "http://portal:5100", entra: "https://entra-local:8443" }); + const expressions = [...routes.matchAll(/location ~ (.+) \{/g)].map((match) => new RegExp(match[1])); + function destination(path: string): string { + if (path === "/graph/oidc/userinfo") return "auth"; + const index = expressions.findIndex((expression) => expression.test(path)); + return ["api", "auth", "denied"][index] || "portal"; + } + + it.each(["/api/v1/users/me", "/api", "/openapi.json", "/api-docs", "/api-docs/", "/health", "/ready", "/about"]) ("routes API path %s before the SPA", (path) => { + expect(destination(path)).toBe("api"); + }); + + it.each([`/${DEFAULT_TENANT}/v2.0/.well-known/openid-configuration`, `/${DEFAULT_TENANT}/discovery/v2.0/keys`, `/${DEFAULT_TENANT}/oauth2/v2.0/authorize`, `/${DEFAULT_TENANT}/oauth2/v2.0/token`, "/graph/oidc/userinfo", "/common/oauth2/v2.0/authorize"]) ("preserves tenant-root auth path %s", (path) => { + expect(destination(path)).toBe("auth"); + }); + + it.each(["/admin", "/admin/api/apps", "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/graph/unknown", `/${DEFAULT_TENANT}/unknown`, "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/common/unknown", "/wrong-tenant/oauth2/v2.0/token"]) ("denies private/unknown auth path %s", (path) => { + expect(destination(path)).toBe("denied"); + }); + + it.each(["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/runs/example", "/apiary", "/healthier", "/about-us"]) ("preserves Portal route %s", (path) => { + expect(destination(path)).toBe("portal"); + }); + + it("enables streaming, upgrades and verified internal TLS", () => { + expect(routes).toContain("listen 8443 ssl;"); + expect(routes).toContain("proxy_buffering off;"); + expect(routes).toContain("proxy_set_header Upgrade $http_upgrade;"); + expect(routes).toContain("proxy_ssl_verify on;"); + expect(routes).not.toContain("/auth/"); + }); + + it("uses HTTP only behind Codespaces external HTTPS termination", () => { + const remote = resolveDevConfig({ CODESPACES: "true", PUBLIC_ORIGIN: "https://example.app.github.dev" }); + const routes = renderEdgeRoutes(remote, { api: "http://api:3000", portal: "http://portal:5100", entra: "https://entra-local:8443" }); + expect(routes).toContain("listen 8080;"); + expect(routes).not.toContain("ssl_certificate "); + }); +}); \ No newline at end of file diff --git a/scripts/dev/config.ts b/scripts/dev/config.ts new file mode 100644 index 000000000..af6c1c5d6 --- /dev/null +++ b/scripts/dev/config.ts @@ -0,0 +1,165 @@ +import { isIP } from "node:net"; + +export const DEFAULT_TENANT = "11111111-1111-1111-1111-111111111111"; +export const SPA_CLIENT_ID = "cccccccc-0000-0000-0000-000000000001"; +export const API_CLIENT_ID = "cccccccc-0000-0000-0000-000000000005"; +export type RuntimeTarget = "native" | "compose" | "kind"; + +export interface RuntimeInputs { + generated?: NodeJS.ProcessEnv; + local?: NodeJS.ProcessEnv; + process?: NodeJS.ProcessEnv; +} + +/** Use one precedence contract for every runtime, without mutating input files. */ +export function resolveRuntimeEnv(inputs: RuntimeInputs, target: RuntimeTarget): Record { + const env = { ...inputs.generated, ...inputs.local, ...inputs.process }; + const config = resolveDevConfig(env); + const host = (service: string): string => target === "native" ? "127.0.0.1" : service; + const port = (key: string, fallback: string): string => String(parsePort(env[key] || fallback)); + const mongoPort = target === "native" ? port("MONGODB_PORT", "27000") : "27017"; + const entraPort = target === "native" ? port("SPIKE_ENTRA_PORT", "18443") : "8443"; + const blobPort = target === "native" ? port("AZURITE_BLOB_PORT", "10100") : "10000"; + const queuePort = target === "native" ? port("AZURITE_QUEUE_PORT", "10200") : "10001"; + const tablePort = target === "native" ? port("AZURITE_TABLE_PORT", "10300") : "10002"; + const storageKey = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="; + const values: Record = { + ...config.auth, + AUTH_PROVIDER: "entra", + AUTH_TENANT_ID: config.tenant, + AUTH_API_CLIENT_ID: API_CLIENT_ID, + AUTH_PORTAL_CLIENT_ID: SPA_CLIENT_ID, + AUTH_JWKS_URI: `https://${target === "native" ? "localhost" : "entra-local"}:${entraPort}/${config.tenant}/discovery/v2.0/keys`, + VITE_AUTH_CLIENT_ID: SPA_CLIENT_ID, + VITE_AUTH_SCOPES: `api://${API_CLIENT_ID}/access_as_user`, + VITE_AUTH_ENABLED_LOCAL: "true", + VITE_DEV_EDGE_ORIGIN: config.publicOrigin, + API_ENDPOINT: `http://${host("api")}:${target === "native" ? port("API_PORT", "3100") : "80"}`, + MONGO_CONNECTION_STRING: `mongodb://${host("mongodb")}:${mongoPort}/?replicaSet=rs0${target === "native" ? "&directConnection=true" : ""}`, + MONGO_DATABASE: "scope-dev", + REDIS_HOST: host("redis"), + REDIS_PORT: target === "native" ? port("REDIS_PORT", "6300") : "6379", + REDIS_PASSWORD: "", + AZURE_STORAGE_ACCOUNT_NAME: "devstoreaccount1", + STORAGE_CONNECTION_STRING: `DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=${storageKey};BlobEndpoint=http://${host("azurite")}:${blobPort}/devstoreaccount1;QueueEndpoint=http://${host("azurite")}:${queuePort}/devstoreaccount1;TableEndpoint=http://${host("azurite")}:${tablePort}/devstoreaccount1;`, + JUDGE_SERVICE_URL: `http://${host("judge")}:${target === "native" ? port("JUDGE_PORT", "3101") : "80"}`, + TOKEN_MANAGER_URL: `http://${host("token-manager")}:${target === "native" ? port("TOKEN_MANAGER_PORT", "3102") : "80"}`, + NODE_TLS_REJECT_UNAUTHORIZED: "1", + WORKER_CONCURRENCY: "1", + }; + values.SCOPE_MT_API_URL = values.API_ENDPOINT; + return values; +} + +/** Public settings are selected explicitly, never serialized from the process environment. */ +export function browserSettings(values: Record): Record { + const keys = ["VITE_AUTH_CLIENT_ID", "VITE_AUTH_SCOPES", "VITE_AUTH_AUTHORITY", "VITE_AUTH_KNOWN_AUTHORITIES", "VITE_AUTH_REDIRECT_URI", "VITE_AUTH_POST_LOGOUT_REDIRECT_URI", "VITE_AUTH_PROTOCOL_MODE", "VITE_AUTH_ENABLED_LOCAL", "VITE_DEV_EDGE_ORIGIN"]; + return Object.fromEntries(keys.map((key) => [key, values[key]])); +} + +export interface DevConfig { + publicOrigin: string; + tenant: string; + edgePort: number; + codespaces: boolean; + auth: Record; +} + +function parsePort(value: string): number { + if (!/^\d+$/.test(value) || Number(value) < 1024 || Number(value) > 65535) { + throw new Error("Edge port must be an integer between 1024 and 65535"); + } + return Number(value); +} + +/** Resolve only explicit inputs, never request Host/forwarded headers. */ +export function resolveDevConfig(env: NodeJS.ProcessEnv): DevConfig { + const codespaces = env.CODESPACES === "true"; + const edgePort = parsePort((codespaces ? env.EDGE_PORT : env.EDGE_TLS_PORT) || (codespaces ? "8080" : "8443")); + const tenant = env.AUTH_TENANT_ID || DEFAULT_TENANT; + if (!/^[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12}$/i.test(tenant)) { + throw new Error("AUTH_TENANT_ID must be a UUID"); + } + + let origin = env.PUBLIC_ORIGIN; + if (!origin && codespaces) { + const name = env.CODESPACE_NAME; + const domain = env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN; + if (!name || !/^[a-z0-9-]+$/.test(name) || !domain || !/^[a-z0-9]+(?:[.-][a-z0-9]+)*\.[a-z]{2,}$/i.test(domain)) { + throw new Error("Codespaces origin requires CODESPACE_NAME and GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN"); + } + origin = `https://${name}-${edgePort}.${domain}`; + } + + const publicUrl = new URL(origin || `https://localhost:${edgePort}`); + if (publicUrl.protocol !== "https:" || publicUrl.username || publicUrl.password || publicUrl.pathname !== "/" || publicUrl.search || publicUrl.hash || !/^[a-z\d]+(?:[.-][a-z\d]+)*$/i.test(publicUrl.hostname) || isIP(publicUrl.hostname)) { + throw new Error("PUBLIC_ORIGIN must be an HTTPS origin with a DNS hostname, no credentials, path, query, or fragment"); + } + if (!codespaces && publicUrl.hostname === "localhost" && Number(publicUrl.port || "443") !== edgePort) { + throw new Error("Local forwarded port must equal EDGE_TLS_PORT; use an explicit port override for parallel containers"); + } + + const publicOrigin = publicUrl.origin; + return { + publicOrigin, tenant, edgePort, codespaces, + auth: { + PUBLIC_ORIGIN: publicOrigin, + ISSUER: `${publicOrigin}/${tenant}/v2.0`, + VITE_AUTH_AUTHORITY: `${publicOrigin}/${tenant}/v2.0`, + VITE_AUTH_KNOWN_AUTHORITIES: publicUrl.host, + VITE_AUTH_REDIRECT_URI: publicOrigin, + VITE_AUTH_POST_LOGOUT_REDIRECT_URI: publicOrigin, + VITE_AUTH_PROTOCOL_MODE: "OIDC", + AUTH_AUTHORITY: `${publicOrigin}/${tenant}`, + AUTH_ISSUER_TEMPLATE: `${publicOrigin}/{tenantid}/v2.0`, + AUTH_JWKS_URI: `https://entra-local:8443/${tenant}/discovery/v2.0/keys`, + }, + }; +} + +/** Render identical route semantics for native, Compose, and Kind upstreams. */ +export function renderEdgeRoutes(config: DevConfig, upstreams: { api: string; portal: string; entra: string }): string { + for (const upstream of Object.values(upstreams)) { + if (!/^https?:\/\/[a-z\d.-]+:\d+$/i.test(upstream)) { + throw new Error("Upstream must be an explicit HTTP(S) hostname and port"); + } + } + + return `map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} +server { + listen ${config.edgePort}${config.codespaces ? "" : " ssl"}; +${config.codespaces ? "" : " ssl_certificate /certs/edge.pem;\n ssl_certificate_key /certs/edge-key.pem;\n"} + server_name ${new URL(config.publicOrigin).hostname}; + client_max_body_size 100m; + proxy_http_version 1.1; + proxy_set_header Host ${new URL(config.publicOrigin).host}; + proxy_set_header X-Forwarded-Proto https; + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; + proxy_buffering off; + proxy_ssl_verify on; + proxy_ssl_trusted_certificate /ca/rootCA.pem; + proxy_ssl_server_name on; + location ~ ^/(?:api(?:/|$)|openapi\\.json$|api-docs(?:/|$)|health$|ready$|about$) { + proxy_pass ${upstreams.api}; + } + location ~ ^/(?:${config.tenant}|common|organizations|consumers)/(?:v2\\.0/\\.well-known/openid-configuration$|discovery/v2\\.0/keys$|oauth2/v2\\.0(?:/|$)) { + proxy_pass ${upstreams.entra}; + } + location = /graph/oidc/userinfo { + proxy_pass ${upstreams.entra}; + } + location ~ ^/(?:admin(?:/|$)|graph(?:/|$)|(?:${config.tenant}|common|organizations|consumers)(?:/|$)|[^/]+/(?:v2\\.0|discovery|oauth2|openid)(?:/|$)) { + return 404; + } + location / { + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_pass ${upstreams.portal}; + } +} +`; +} \ No newline at end of file diff --git a/scripts/dev/control.ts b/scripts/dev/control.ts new file mode 100644 index 000000000..8ca015431 --- /dev/null +++ b/scripts/dev/control.ts @@ -0,0 +1,329 @@ +import { execFileSync, spawn } from "node:child_process"; +import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, statfsSync, writeFileSync } from "node:fs"; +import { cpus, totalmem } from "node:os"; +import { resolve } from "node:path"; +import { setTimeout as delay } from "node:timers/promises"; +import { fileURLToPath } from "node:url"; +import { parseEnv } from "node:util"; +import { browserSettings, resolveDevConfig, resolveRuntimeEnv, type RuntimeInputs } from "./config.js"; +import { runtimeByName, runtimes, type RuntimeEntry } from "./inventory.js"; +import { workspaceName } from "./spike.js"; + +export const root = resolve(fileURLToPath(new URL("../..", import.meta.url))); +export const stateDirectory = resolve(root, ".dev-state/runtime"); +export const project = workspaceName(root).replace("spike", "dev"); + +interface ManagedProcess { pid: number; identity: string } +interface State { mode: "native" | "kind"; active: boolean; restore: boolean; services?: string[]; phase?: "starting" | "ready" | "failed"; processes: Record } + +/** Preserve ownership on failure; an explicit down is required before changing modes. */ +export function startupState(previous: State | undefined, mode: State["mode"], services: string[] | undefined, restore: boolean): State { + if (previous?.active && previous.mode !== mode) throw new Error(`Mode ${previous.mode} is active; run dev:down before switching`); + const selected = services ?? (previous?.mode === mode ? previous.services : undefined) ?? (mode === "native" ? ["api", "portal"] : ["api", "portal", "judge", "token-manager", "scheduler", "gateway"]); + for (const name of selected) runtimeByName(name); + return { mode, active: true, restore, services: selected, phase: "starting", processes: previous?.mode === mode ? { ...previous.processes } : {} }; +} + +export function loadInputs(directory = root, processEnv = process.env): RuntimeInputs { + const load = (name: string): NodeJS.ProcessEnv => { + const path = resolve(directory, name); + return existsSync(path) ? parseEnv(readFileSync(path, "utf8")) : {}; + }; + return { generated: load(".env"), local: load(".env.local"), process: processEnv }; +} + +function mergedInputs(inputs = loadInputs()): NodeJS.ProcessEnv { + return { ...inputs.generated, ...inputs.local, ...inputs.process }; +} + +/** Forward ambient tool settings, never ambient provider secrets or global inspector options. */ +export function consumerEnvironment(entry: RuntimeEntry, inputs: RuntimeInputs, settings: Record): NodeJS.ProcessEnv { + const source = mergedInputs(inputs); + const ambient = ["PATH", "HOME", "USER", "SHELL", "TERM", "LANG", "CI", "PNPM_HOME", "COREPACK_HOME", "CARGO_HOME", "RUSTUP_HOME", "VIRTUAL_ENV", "DISPLAY"]; + const keys = [...ambient, ...(entry.secrets || [])]; + const selected = Object.fromEntries(keys.filter((key) => source[key] !== undefined).map((key) => [key, source[key]])); + return { ...selected, ...(entry.name === "portal" || entry.name === "storybook" ? browserSettings(settings) : settings) }; +} + +export function execute(command: string, args: string[], env = process.env, cwd = root, timeout = 900_000): void { + execFileSync(command, args, { stdio: "inherit", env, cwd, timeout }); +} + +function output(command: string, args: string[], env = process.env): string { + return execFileSync(command, args, { encoding: "utf8", env, cwd: root, timeout: 30_000 }).trim(); +} + +function processIdentity(pid: number): string { + try { + const fields = readFileSync(`/proc/${pid}/stat`, "utf8").split(") ")[1].split(" "); + return fields[0] === "Z" ? "" : fields[19]; + } + catch { return ""; } +} + +function readState(): State | undefined { + const path = resolve(stateDirectory, "mode.json"); + if (!existsSync(path)) return; + const value: unknown = JSON.parse(readFileSync(path, "utf8")); + if (!value || typeof value !== "object" || !("mode" in value) || (value.mode !== "native" && value.mode !== "kind") || !("processes" in value) || typeof value.processes !== "object" || !value.processes) throw new Error("Invalid runtime state; inspect .dev-state/runtime/mode.json before continuing"); + return value as State; +} + +function saveState(state: State): void { + mkdirSync(stateDirectory, { recursive: true, mode: 0o700 }); + const path = resolve(stateDirectory, "mode.json"); + writeFileSync(`${path}.tmp`, JSON.stringify(state, null, 2), { mode: 0o600 }); + renameSync(`${path}.tmp`, path); +} + +function compose(env: NodeJS.ProcessEnv, ...args: string[]): void { + execute("docker", ["compose", "--project-name", project, "--env-file", "/dev/null", "--file", resolve(root, ".devcontainer/native.compose.yaml"), ...args], env); +} + +function spike(env: NodeJS.ProcessEnv, command: string): void { + execute("pnpm", ["exec", "tsx", "scripts/dev/spike.ts", command], env); +} + +/** Separate local vault PKI from Entra's CA; never disable client certificate checks. */ +function prepareVault(env: NodeJS.ProcessEnv): void { + const certs = resolve(stateDirectory, "certs"); + mkdirSync(certs, { recursive: true, mode: 0o755 }); + const authority = resolve(process.env.SCOPE_DEV_DATA || stateDirectory, "lowkey-authority"); + mkdirSync(authority, { recursive: true, mode: 0o700 }); + const certEnv = { ...env, CAROOT: authority }; + execute("mkcert", ["-cert-file", resolve(certs, "lowkey.pem"), "-key-file", resolve(certs, "lowkey-key.pem"), "localhost", "lowkey-vault"], certEnv); + execute("openssl", ["pkcs12", "-export", "-in", resolve(certs, "lowkey.pem"), "-inkey", resolve(certs, "lowkey-key.pem"), "-out", resolve(certs, "lowkey.p12"), "-name", "lowkey-vault", "-passout", "pass:scope-local-development"]); + writeFileSync(resolve(certs, "lowkey-ca.pem"), readFileSync(resolve(authority, "rootCA.pem"))); +} + +function servicePort(entry: RuntimeEntry, env: NodeJS.ProcessEnv): number | undefined { + if (!entry.port) return; + const port = Number(env[`${entry.name.toUpperCase().replaceAll("-", "_")}_PORT`] || entry.port); + if (!Number.isInteger(port) || port < 1024 || port > 65535) throw new Error(`Invalid ${entry.name} port`); + return port; +} + +export function launchCommand(entry: RuntimeEntry, debug: boolean, args: string[] = []): string[] { + if (entry.name === "tests") return debug ? ["node", `--inspect-brk=127.0.0.1:${entry.inspector}`, "node_modules/vitest/vitest.mjs", "run", "--no-file-parallelism", ...args] : ["pnpm", "exec", "vitest", "run", ...args]; + if (entry.name === "prompt-evaluations") return ["pnpm", "--filter", "static-prompt-evals", "evaluate:quality", ...args]; + if (entry.name === "storybook") return ["pnpm", "--filter", "portal", "storybook", ...args]; + if (entry.name === "website") return debug ? ["node", `--inspect-brk=127.0.0.1:${entry.inspector}`, "node_modules/astro/astro.js", "dev", ...args] : ["pnpm", "dev", ...args]; + if (entry.name === "portal") return ["pnpm", "--filter", "portal", "dev", "--host", "127.0.0.1", "--strictPort", ...args]; + if (entry.kind === "rust") return ["cargo", "run", "--locked", "--", "--port", "18000", "--api-port", "18897", ...args]; + if (!entry.entry) throw new Error(`Missing entrypoint for ${entry.name}`); + return ["node", ...(debug ? [`--inspect-brk=127.0.0.1:${entry.inspector}`] : entry.kind === "service" ? ["--watch"] : []), "--conditions=source", "--enable-source-maps", "--import", "tsx", resolve(root, entry.directory, entry.entry), ...(entry.name === "db-migrations" && !args.length ? ["up"] : entry.name === "cli" && !args.length ? ["--help"] : args)]; +} + +async function startNative(name: string, state: State, env: NodeJS.ProcessEnv): Promise { + const existing = state.processes[name]; + if (existing && processIdentity(existing.pid) === existing.identity) return; + const log = openSync(resolve(stateDirectory, `${name}.log`), "a", 0o600); + const child = spawn("pnpm", ["exec", "tsx", "scripts/dev/control.ts", "run", `--service=${name}`], { cwd: root, env, detached: true, stdio: ["ignore", log, log] }); + await new Promise((resolvePromise, reject) => { child.once("spawn", resolvePromise); child.once("error", reject); }); + closeSync(log); + if (!child.pid) throw new Error(`Could not launch ${name}`); + state.processes[name] = { pid: child.pid, identity: processIdentity(child.pid) }; + child.unref(); + saveState(state); +} + +async function stopNative(state: State): Promise { + for (const [name, managed] of Object.entries(state.processes)) { + if (processIdentity(managed.pid) !== managed.identity) continue; + process.kill(-managed.pid, "SIGTERM"); + const deadline = Date.now() + 60_000; + while (processIdentity(managed.pid) === managed.identity && Date.now() < deadline) await delay(200); + if (processIdentity(managed.pid) === managed.identity) throw new Error(`${name} has not stopped gracefully; inspect it before resetting data`); + } + state.processes = {}; +} + +async function waitForNative(name: string, state: State, env: NodeJS.ProcessEnv): Promise { + const entry = runtimeByName(name); + if (name !== "api" && name !== "portal") return; + const url = `http://127.0.0.1:${servicePort(entry, env)}${name === "api" ? "/ready" : "/"}`; + const deadline = Date.now() + 90_000; + while (Date.now() < deadline) { + const managed = state.processes[name]; + if (!managed || processIdentity(managed.pid) !== managed.identity) throw new Error(`${name} exited during startup; run pnpm dev:logs --service=${name}`); + try { if ((await fetch(url, { signal: AbortSignal.timeout(2000) })).ok) return; } + catch { /* The process may still be binding its listener. */ } + await delay(500); + } + throw new Error(`${name} did not become ready at ${url}; run pnpm dev:logs --service=${name}`); +} + +async function main(): Promise { + const command = process.argv[2] || "doctor"; + const option = (name: string): string | undefined => process.argv.find((argument) => argument.startsWith(`--${name}=`))?.slice(name.length + 3); + const inputs = loadInputs(); + const inputEnv = mergedInputs(inputs); + const config = resolveDevConfig(inputEnv); + const settings = resolveRuntimeEnv(inputs, "native"); + const env = { ...inputEnv, ...settings, DEV_CERT_DIR: resolve(stateDirectory, "certs"), COMPOSE_PARALLEL_LIMIT: "2" }; + mkdirSync(stateDirectory, { recursive: true, mode: 0o700 }); + if (command === "doctor" || command === "status") { + console.log(`Workspace: ${project}\nOrigin: ${config.publicOrigin}\nMode: ${readState()?.mode || "not selected"}`); + const disk = statfsSync(root); + console.log(`CPUs ${cpus().length}; RAM ${(totalmem() / 2 ** 30).toFixed(1)} GiB; available disk ${(disk.bavail * disk.bsize / 2 ** 30).toFixed(1)} GiB`); + if (cpus().length < 4 || totalmem() < 15 * 2 ** 30) console.warn("Below the initial 4-core/16-GB fast-mode sizing target"); + if (disk.bavail * disk.bsize < 80 * 2 ** 30) console.warn("Below the 80-GB available-disk full-Kind sizing target; full builds may exhaust disk"); + for (const tool of ["docker", "kind", "kubectl", "mkcert", "cargo", "uv", "helm", "skaffold", "az", "pwsh", "gh"]) { + try { console.log(`${tool}: ${output("sh", ["-c", 'command -v "$1"', "--", tool])}`); } + catch { console.warn(`${tool}: unavailable`); } + } + console.log(`Docker: ${output("docker", ["info", "--format", "{{.ServerVersion}}"])}; live provider credentials/entitlements are not validated.`); + return; + } + if (command === "config") { + for (const target of ["native", "compose", "kind"] as const) writeFileSync(resolve(stateDirectory, `${target}.json`), JSON.stringify(resolveRuntimeEnv(inputs, target), null, 2)); + console.log(`Generated non-secret settings in ${stateDirectory}`); + return; + } + if (command === "workers") { + const state = readState(); + if (!state?.active || state.mode !== "native" || state.phase !== "ready") throw new Error("Start native mode successfully before launching container workers"); + const selected = option("services")?.split(","); + if (!selected?.length) throw new Error("Select workers explicitly with --services=; this may consume provider credits"); + const workers = await import("./workers.js"); + const model = workers.renderNativeWorkers(workers.existingWorkerModel(root, inputEnv), selected, inputs, project); + const path = resolve(stateDirectory, "workers.json"); + writeFileSync(path, JSON.stringify(model, null, 2), { mode: 0o600 }); + execute("pnpm", ["exec", "tsx", "scripts/dev/bootstrap.ts", "register-agents"], env); + execute("docker", ["compose", "--project-name", project, "--file", path, "up", "--detach", ...(process.argv.includes("--build") ? ["--build"] : [])], { ...env, COMPOSE_PARALLEL_LIMIT: "1" }, root, 0); + return; + } + if (command === "images" || command === "job") { + const cluster = await import("./cluster.js"); + if (command === "images") cluster.buildImages(env, process.argv.includes("--all") ? ["tools", ...runtimes.filter((entry) => entry.dockerfile).map((entry) => entry.name)] : (option("services") || "tools,api").split(",")); + else { + const name = option("service") || "tests"; + const entry = runtimeByName(name); + if (entry.kind !== "utility" && entry.kind !== "tool") throw new Error("dev:job requires a one-shot tool or utility"); + cluster.kubectl(["patch", "job", name, "--type=merge", "-p", '{"spec":{"suspend":false}}'], env); + cluster.kubectl(["wait", "--for=condition=complete", `job/${name}`, "--timeout=600s"], env); + } + return; + } + if (command === "start" || command === "attach" || command === "create") { + if (command === "create") { + execute("pnpm", ["install", "--frozen-lockfile"]); + execute("pnpm", ["-r", "--filter", "./packages/**", "--if-present", "build"]); + execute("pnpm", ["--dir", "website", "install", "--frozen-lockfile"]); + execute("uv", ["venv", "--python", "3.11", resolve(root, ".venv")]); + execute("uv", ["pip", "install", "--python", resolve(root, ".venv/bin/python"), "debugpy==1.8.14"]); + for (const name of ["github-auth", "github-cookie-updater"]) execute("pnpm", ["--filter", name, "exec", "playwright", "install", "chromium"]); + execute("pnpm", ["--dir", "website", "exec", "playwright", "install", "chromium"]); + execute("pnpm", ["dev:config"]); + } else if (command === "start") { + let ready = false; + for (let attempt = 0; attempt < 30; attempt++) { + try { output("docker", ["info", "--format", "{{.ServerVersion}}"]); ready = true; break; } + catch { await delay(1000); } + } + if (!ready) throw new Error("Docker is not ready; check outer-container privileged support"); + const saved = readState(); + if (saved?.restore) execute("pnpm", ["dev:up", `--mode=${saved.mode}`, ...(saved.services ? [`--services=${saved.services.join(",")}`] : []), "--restore"], process.env, root, 0); + } + console.log(`Scope development: ${config.publicOrigin}\nMode ${readState()?.mode || "not selected"}. Use pnpm dev:doctor for diagnostics.`); + return; + } + if (command === "run") { + const entry = runtimeByName(option("service") || "api"); + const forwarded = process.argv.includes("--") ? process.argv.slice(process.argv.indexOf("--") + 1) : []; + if (option("mode") === "kind") { + if (!process.argv.includes("--debug")) throw new Error("Use dev:debug for a Kind inspector session, or dev:job for one-shot execution"); + const cluster = await import("./cluster.js"); + await cluster.debugRuntime(inputEnv, entry.name, forwarded); + return; + } + const selected = consumerEnvironment(entry, inputs, settings); + selected.PORT = String(servicePort(entry, inputEnv) || "3000"); + selected.NODE_EXTRA_CA_CERTS = resolve(root, ".dev-state/spike/certs/rootCA.pem"); + if (entry.name === "token-manager") { + selected.NODE_EXTRA_CA_CERTS = resolve(stateDirectory, "certs/lowkey-ca.pem"); + selected.AZURE_KEYVAULT_URI = `https://localhost:${inputEnv.LOWKEY_VAULT_PORT || "18444"}`; + selected.IDENTITY_ENDPOINT = `http://localhost:${inputEnv.LOWKEY_IDENTITY_PORT || "18082"}/metadata/identity/oauth2/token`; + selected.IDENTITY_HEADER = "header"; + } + const [executable, ...args] = launchCommand(entry, process.argv.includes("--debug"), entry.name === "portal" ? ["--port", selected.PORT, ...forwarded] : forwarded); + execute(executable, args, selected, entry.name === "website" || entry.kind === "rust" ? resolve(root, entry.directory) : root, 0); + return; + } + const state = readState(); + if (command === "logs") { + const name = option("service") || "api"; + runtimeByName(name); + const path = resolve(stateDirectory, `${name}.log`); + if (existsSync(path)) execute("tail", ["-n", "100", path]); + else compose(env, "logs", "--tail", "100"); + return; + } + if (command === "down" || command === "reset-data") { + if (command === "reset-data" && option("confirm") !== project) throw new Error(`Destructive reset requires --confirm=${project}`); + if (state?.mode === "kind") { + const cluster = await import("./cluster.js"); + execute("kind", ["delete", "cluster", "--name", project, "--kubeconfig", cluster.kubeconfig], env); + saveState({ ...state, active: false, restore: false }); + if (command === "reset-data") throw new Error("Kind node deleted; retained host-mounted state was not deleted. Back it up and remove only the workspace state directory explicitly."); + return; + } + if (state) await stopNative(state); + const workers = resolve(stateDirectory, "workers.json"); + if (existsSync(workers)) execute("docker", ["compose", "--project-name", project, "--file", workers, "down", "--timeout", "120", ...(command === "reset-data" ? ["--volumes"] : [])], env); + compose(env, "down", "--timeout", "60", ...(command === "reset-data" ? ["--volumes"] : [])); + spike(env, "down"); + if (command === "reset-data") execute("pnpm", ["exec", "tsx", "scripts/dev/spike.ts", "reset-data", `--confirm=${workspaceName(root)}`], env); + if (state) saveState({ ...state, active: false, restore: false }); + return; + } + if (command !== "up") throw new Error("Usage: pnpm dev:"); + const mode = option("mode") || "native"; + if (mode !== "native" && mode !== "kind") throw new Error("Mode must be native or kind"); + if (state?.active && state.mode !== mode) throw new Error(`Mode ${state.mode} is active; run dev:down before switching`); + const next = startupState(state, mode, option("services")?.split(","), process.argv.includes("--restore")); + const lock = resolve(stateDirectory, "operation.lock"); + try { mkdirSync(lock); } catch { throw new Error("Another lifecycle operation is active; inspect .dev-state/runtime/operation.lock"); } + try { + saveState(next); + prepareVault(env); + if (mode === "kind") { + spike(env, "config"); + if (!existsSync(resolve(root, ".dev-state/spike/certs/edge.pem"))) { + spike(env, "up"); + spike(env, "down"); + } + const cluster = await import("./cluster.js"); + cluster.startCluster(inputEnv, next.services!, process.argv.includes("--build")); + next.phase = "ready"; + saveState(next); + return; + } + compose(env, "up", "--detach", "--wait", "--wait-timeout", "180", "mongodb", "redis", "azurite", "lowkey-vault"); + compose(env, "run", "--rm", "mongo-init"); + execute("pnpm", ["-r", "--filter", "./packages/**", "--if-present", "build"], env); + execute("pnpm", ["--filter", "db-migrations", "migrate:up"], env); + execute("pnpm", ["exec", "tsx", "scripts/dev/bootstrap.ts", "storage-init"], env); + const edge = output("docker", ["ps", "--filter", `label=com.docker.compose.project=${workspaceName(root)}`, "--filter", "label=com.docker.compose.service=dev-edge", "--format", "{{.ID}}"]); + spike(env, "config"); + spike(env, edge ? "probe" : "up"); + for (const name of next.services!) { + const entry = runtimeByName(name); + if (!entry.native || entry.kind === "tool") throw new Error(`${name} requires an explicit on-demand/container launch`); + await startNative(name, next, env); + } + for (const name of next.services!) await waitForNative(name, next, inputEnv); + next.phase = "ready"; + saveState(next); + console.log(`Development processes ready. Browser: ${config.publicOrigin}\nLogs: pnpm dev:logs --service=api`); + } catch (error) { + next.phase = "failed"; + next.restore = false; + saveState(next); + throw error; + } finally { rmSync(lock, { recursive: true }); } +} + +if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { + main().catch((error: unknown) => { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1; }); +} \ No newline at end of file diff --git a/scripts/dev/inventory.ts b/scripts/dev/inventory.ts new file mode 100644 index 000000000..d03382e6d --- /dev/null +++ b/scripts/dev/inventory.ts @@ -0,0 +1,42 @@ +export interface RuntimeEntry { + name: string; + directory: string; + kind: "service" | "worker" | "utility" | "tool" | "rust"; + port?: number; + inspector?: number; + entry?: string; + dockerfile?: string; + native?: boolean; + secrets?: string[]; +} + +/** Reviewed runtime inventory shared by startup, image builds, and debugger routing. */ +export const runtimes: RuntimeEntry[] = [ + { name: "api", directory: "apps/api", kind: "service", port: 3100, inspector: 9230, entry: "src/index.ts", dockerfile: "apps/api/Dockerfile", native: true, secrets: ["GITHUB_MODELS_API_KEY", "AZURE_AI_INFERENCE_ENDPOINT", "AZURE_AI_INFERENCE_API_KEY"] }, + { name: "portal", directory: "apps/portal", kind: "service", port: 5100, native: true }, + { name: "judge", directory: "apps/judge", kind: "service", port: 3101, inspector: 9231, entry: "src/index.ts", dockerfile: "apps/judge/Dockerfile", native: true, secrets: ["GITHUB_TOKEN"] }, + { name: "token-manager", directory: "apps/token-manager", kind: "service", port: 3102, inspector: 9232, entry: "src/index.ts", dockerfile: "apps/token-manager/Dockerfile", native: true }, + { name: "scheduler", directory: "apps/scheduler", kind: "service", port: 3103, inspector: 9233, entry: "src/index.ts", dockerfile: "apps/scheduler/Dockerfile", native: true }, + { name: "gateway", directory: "apps/gateway", kind: "rust", port: 18000, dockerfile: "apps/gateway/Dockerfile", native: true }, + { name: "coder-acp-copilot", directory: "apps/workers/coder-acp-copilot", kind: "worker", inspector: 9240, entry: "src/index.ts", dockerfile: "apps/workers/coder-acp-copilot/Dockerfile", secrets: ["GITHUB_TOKEN"] }, + { name: "coder-acp-claude-code", directory: "apps/workers/coder-acp-claude-code", kind: "worker", inspector: 9241, entry: "src/index.ts", dockerfile: "apps/workers/coder-acp-claude-code/Dockerfile", secrets: ["ANTHROPIC_API_KEY"] }, + { name: "report-generator", directory: "apps/workers/report-generator", kind: "worker", inspector: 9242, entry: "src/index.ts", dockerfile: "apps/workers/report-generator/Dockerfile", secrets: ["GITHUB_TOKEN"] }, + { name: "post-processor", directory: "apps/workers/post-processor", kind: "worker", inspector: 9243, entry: "src/index.ts", dockerfile: "apps/workers/post-processor/Dockerfile" }, + { name: "model-scanner-copilot", directory: "apps/model-scanners/copilot", kind: "utility", inspector: 9250, entry: "src/index.ts", dockerfile: "apps/model-scanners/copilot/Dockerfile", secrets: ["GITHUB_TOKEN"] }, + { name: "model-scanner-anthropic", directory: "apps/model-scanners/anthropic", kind: "utility", inspector: 9251, entry: "src/index.ts", dockerfile: "apps/model-scanners/anthropic/Dockerfile", secrets: ["ANTHROPIC_API_KEY"] }, + { name: "version-checker-acp-copilot", directory: "apps/version-checkers/acp-copilot", kind: "utility", inspector: 9252, entry: "src/check-versions.ts", secrets: ["GITHUB_TOKEN"] }, + { name: "version-checker-claude-code", directory: "apps/version-checkers/claude-code", kind: "utility", inspector: 9253, entry: "src/check-versions.ts", secrets: ["GITHUB_TOKEN"] }, + { name: "github-cookie-updater", directory: "apps/key-updaters/github-cookie-updater", kind: "utility", inspector: 9254, entry: "src/github-cookie-updater.ts", secrets: ["GITHUB_USERNAME", "GITHUB_PASSWORD", "GITHUB_TOTP_SECRET"] }, + { name: "cli", directory: "apps/cli", kind: "tool", inspector: 9260, entry: "src/index.ts", native: true, secrets: ["SCOPE_TOKEN"] }, + { name: "db-migrations", directory: "packages/db-migrations", kind: "tool", inspector: 9261, entry: "src/migrate.ts", native: true }, + { name: "tests", directory: ".", kind: "tool", inspector: 9262, native: true }, + { name: "prompt-evaluations", directory: "evaluations/static-prompts", kind: "tool", native: true }, + { name: "storybook", directory: "apps/portal", kind: "tool", port: 6100, native: true }, + { name: "website", directory: "website", kind: "tool", port: 4321, inspector: 9263, native: true }, +]; + +export function runtimeByName(name: string): RuntimeEntry { + const entry = runtimes.find((runtime) => runtime.name === name); + if (!entry) throw new Error(`Unknown runtime ${name}; available: ${runtimes.map((runtime) => runtime.name).join(", ")}`); + return entry; +} \ No newline at end of file diff --git a/scripts/dev/kind.test.ts b/scripts/dev/kind.test.ts new file mode 100644 index 000000000..f2124ce81 --- /dev/null +++ b/scripts/dev/kind.test.ts @@ -0,0 +1,42 @@ +import { describe, expect, it } from "vitest"; +import { renderKindStack } from "./kind.js"; +import { runtimes } from "./inventory.js"; +import { inspectorCommand } from "./cluster.js"; + +describe("complete Kind stack", () => { + const resources = renderKindStack({}); + const text = JSON.stringify(resources); + it("pauses before entry without overlapping watchers or duplicate inspectors", () => { + expect(inspectorCommand(["node", "--watch", "--inspect=9229", "--import", "tsx", "apps/api/src/index.ts"], 9230)).toEqual(["node", "--inspect-brk=0.0.0.0:9230", "--import", "tsx", "apps/api/src/index.ts"]); + expect(() => inspectorCommand(["cargo", "run"], 9230)).toThrow(/Node entrypoint/); + }); + it("includes a workload target and named identity for every Linux runtime", () => { + for (const runtime of runtimes) { + expect(resources.some((resource) => (resource.kind === "Deployment" || resource.kind === "Job") && (resource.metadata as { name: string }).name === runtime.name)).toBe(true); + expect(resources.some((resource) => resource.kind === "ServiceAccount" && (resource.metadata as { name: string }).name === runtime.name)).toBe(true); + } + }); + it("does not mount an outer runtime socket, developer kubeconfig or privileged identity", () => { + expect(text).not.toContain("docker.sock"); + expect(text).not.toContain("containerd.sock"); + expect(text).not.toContain("cluster-admin"); + expect(text).not.toContain('"privileged":true'); + for (const resource of resources.filter((resource) => resource.kind === "ServiceAccount")) expect(resource.automountServiceAccountToken).toBe(false); + }); + it("retains persistent state and suspends utility/model Jobs", () => { + expect(resources.filter((resource) => resource.kind === "PersistentVolume")).toHaveLength(6); + for (const resource of resources.filter((resource) => resource.kind === "Job")) expect((resource.spec as { suspend: boolean }).suspend).toBe(true); + const scanner = resources.find((resource) => resource.kind === "Job" && (resource.metadata as { name: string }).name === "model-scanner-copilot"); + expect((scanner?.spec as { suspend: boolean }).suspend).toBe(true); + expect(text).toContain('"nodePort":30080'); + expect(text).toContain("--LOWKEY_IMPORT_LOCATION=/data/export.json"); + expect(text).toContain('"runAsUser":1000'); + }); + it("keeps an overridden tenant and local TLS listener aligned with cluster routing", () => { + const tenant = "22222222-2222-2222-2222-222222222222"; + const local = JSON.stringify(renderKindStack({ AUTH_TENANT_ID: tenant })); + expect(local).toContain(`"name":"TENANT_ID","value":"${tenant}"`); + expect(local).toContain("listen 8080 ssl"); + expect(local).toContain('"targetPort":8080'); + }); +}); \ No newline at end of file diff --git a/scripts/dev/kind.ts b/scripts/dev/kind.ts new file mode 100644 index 000000000..cf3d0aa4d --- /dev/null +++ b/scripts/dev/kind.ts @@ -0,0 +1,108 @@ +import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; +import { resolve } from "node:path"; +import { fileURLToPath } from "node:url"; +import { DEFAULT_TENANT, renderEdgeRoutes, resolveDevConfig, resolveRuntimeEnv } from "./config.js"; +import { runtimes, type RuntimeEntry } from "./inventory.js"; + +type Resource = Record; +export const namespace = "scope-dev"; +const entraImage = "ghcr.io/cmaneu/entra-local@sha256:70584ef110914d100409cb3d63a63548ccdde10ca780f9751755f1482dec5d7e"; +const edgeImage = "nginx@sha256:5b4900b042ccfa8b0a73df622c3a60f2322faeb2be800cbee5aa7b44d241649e"; + +function identity(name: string): Resource { + return { apiVersion: "v1", kind: "ServiceAccount", metadata: { name, namespace }, automountServiceAccountToken: false }; +} + +function service(name: string, port: number, targetPort = port): Resource { + return { apiVersion: "v1", kind: "Service", metadata: { name, namespace }, spec: { selector: { app: name }, ports: [{ name: "http", port, targetPort }] } }; +} + +function deployment(name: string, image: string, container: Resource, pod: Resource = {}): Resource { + return { apiVersion: "apps/v1", kind: "Deployment", metadata: { name, namespace }, spec: { replicas: 1, selector: { matchLabels: { app: name } }, template: { metadata: { labels: { app: name } }, spec: { serviceAccountName: name, automountServiceAccountToken: false, terminationGracePeriodSeconds: 120, containers: [{ name, image, imagePullPolicy: image.startsWith("scope-local/") ? "Never" : "IfNotPresent", resources: { requests: { cpu: "100m", memory: "128Mi" }, limits: { cpu: "2", memory: "2Gi" } }, ...container }], ...pod } } } }; +} + +function claim(name: string): Resource[] { + return [ + { apiVersion: "v1", kind: "PersistentVolume", metadata: { name: `scope-dev-${name}` }, spec: { capacity: { storage: "20Gi" }, accessModes: ["ReadWriteOnce"], persistentVolumeReclaimPolicy: "Retain", storageClassName: "", hostPath: { path: `/scope-state/${name}`, type: "DirectoryOrCreate" }, claimRef: { name, namespace } } }, + { apiVersion: "v1", kind: "PersistentVolumeClaim", metadata: { name, namespace }, spec: { storageClassName: "", volumeName: `scope-dev-${name}`, accessModes: ["ReadWriteOnce"], resources: { requests: { storage: "20Gi" } } } }, + ]; +} + +function job(name: string, image: string, command: string[], suspended = true): Resource { + return { apiVersion: "batch/v1", kind: "Job", metadata: { name, namespace }, spec: { suspend: suspended, backoffLimit: 2, activeDeadlineSeconds: 600, template: { metadata: { labels: { app: name } }, spec: { serviceAccountName: name, automountServiceAccountToken: false, restartPolicy: "Never", containers: [{ name, image, imagePullPolicy: image.startsWith("scope-local/") ? "Never" : "IfNotPresent", command, envFrom: [{ configMapRef: { name: "scope-runtime" } }], volumeMounts: [{ name: "public-ca", mountPath: "/ca", readOnly: true }] }], volumes: [{ name: "public-ca", configMap: { name: "public-ca" } }] } } } }; +} + +function appCommand(entry: RuntimeEntry): string[] { + if (entry.name === "portal") return ["pnpm", "--filter", "portal", "dev", "--host", "0.0.0.0", "--port", "5100", "--strictPort"]; + if (entry.name === "website") return ["pnpm", "--dir", "website", "exec", "astro", "dev", "--host", "0.0.0.0"]; + if (entry.name === "storybook") return ["pnpm", "--filter", "portal", "exec", "storybook", "dev", "--host", "0.0.0.0", "--port", "6100", "--no-open"]; + if (entry.name === "tests") return ["pnpm", "exec", "vitest", "run"]; + if (entry.name === "prompt-evaluations") return ["pnpm", "eval:static-prompts:smoke"]; + return ["node", ...(entry.kind === "service" ? ["--watch"] : []), "--conditions=source", "--enable-source-maps", "--import", "tsx", `${entry.directory}/${entry.entry}`, ...(entry.name === "db-migrations" ? ["up"] : entry.name === "cli" ? ["--help"] : [])]; +} + +/** Render the complete local stack; live consumers and scheduled utilities remain opt-in. */ +export function renderKindStack(env: NodeJS.ProcessEnv = {}): Resource[] { + const config = resolveDevConfig(env); + const settings = { ...resolveRuntimeEnv({ process: env }, "kind"), PORT: "80", NODE_EXTRA_CA_CERTS: "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/ca/rootCA.pem", AZURE_KEYVAULT_URI: "https://lowkey-vault:8443", IDENTITY_ENDPOINT: "http://lowkey-vault:8080/metadata/identity/oauth2/token", IDENTITY_HEADER: "header" }; + const edgeConfig = renderEdgeRoutes({ ...config, edgePort: 8080 }, { api: "http://api:80", portal: "http://portal:5100", entra: "https://entra-local:8443" }); + const resources: Resource[] = [ + { apiVersion: "v1", kind: "Namespace", metadata: { name: namespace } }, + { apiVersion: "v1", kind: "ConfigMap", metadata: { name: "scope-runtime", namespace }, data: settings }, + { apiVersion: "v1", kind: "ConfigMap", metadata: { name: "dev-edge", namespace }, data: { "default.conf": edgeConfig } }, + ...["mongodb", "redis", "azurite", "lowkey-vault", "entra-local", "agent-workspaces"].flatMap(claim), + ]; + const volume = (name: string): Resource => ({ name: "data", persistentVolumeClaim: { claimName: name } }); + const mount = [{ name: "data", mountPath: "/data" }]; + resources.push(identity("mongodb"), service("mongodb", 27017), deployment("mongodb", "mongo:7.0.17", { command: ["mongod", "--replSet", "rs0", "--bind_ip_all", "--dbpath", "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/data/db"], volumeMounts: mount, readinessProbe: { exec: { command: ["mongosh", "--quiet", "--eval", "db.adminCommand({ping:1}).ok || quit(1)"] }, periodSeconds: 3 } }, { volumes: [volume("mongodb")] })); + resources.push(identity("mongo-init"), job("mongo-init", "mongo:7.0.17", ["mongosh", "--host", "mongodb", "--quiet", "--eval", "for(let attempt=0;attempt<90;attempt++){try{try{rs.status()}catch(error){if(error.code!==94)throw error;rs.initiate({_id:'rs0',members:[{_id:0,host:'mongodb:27017'}]})}if(db.hello().isWritablePrimary)quit(0)}catch(error){print(error.message)}await new Promise(resolve=>setTimeout(resolve,2000))}quit(1)"])); + resources.push(identity("redis"), service("redis", 6379), deployment("redis", "redis:7.4.2-alpine", { command: ["redis-server", "--appendonly", "yes"], volumeMounts: mount, readinessProbe: { exec: { command: ["redis-cli", "ping"] }, periodSeconds: 3 } }, { volumes: [volume("redis")] })); + resources.push(identity("azurite"), { apiVersion: "v1", kind: "Service", metadata: { name: "azurite", namespace }, spec: { selector: { app: "azurite" }, ports: [10000, 10001, 10002].map((port) => ({ name: `port-${port}`, port })) } }, deployment("azurite", "mcr.microsoft.com/azure-storage/azurite:3.29.0", { command: ["azurite", "--skipApiVersionCheck", "--loose", "--blobHost", "0.0.0.0", "--queueHost", "0.0.0.0", "--tableHost", "0.0.0.0", "--location", "/data"], volumeMounts: mount, readinessProbe: { tcpSocket: { port: 10001 }, periodSeconds: 3 } }, { volumes: [volume("azurite")] })); + const leafVolumes = [{ name: "certificates", secret: { secretName: "development-certificates" } }, { name: "public-ca", configMap: { name: "public-ca" } }]; + const leafMounts = [{ name: "certificates", mountPath: "/certs", readOnly: true }, { name: "public-ca", mountPath: "/ca", readOnly: true }]; + resources.push(identity("entra-local"), service("entra-local", 8443), deployment("entra-local", entraImage, { env: [{ name: "PUBLIC_ORIGIN", value: config.publicOrigin }, { name: "ISSUER", value: `${config.publicOrigin}/${config.tenant}/v2.0` }, { name: "TLS_ENABLED", value: "true" }, { name: "TLS_CERT", value: "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/certs/edge.pem" }, { name: "TLS_KEY", value: "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/certs/edge-key.pem" }], volumeMounts: [...leafMounts, { name: "data", mountPath: "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/app/data" }], readinessProbe: { tcpSocket: { port: 8443 }, periodSeconds: 3 } }, { volumes: [...leafVolumes, volume("entra-local")], securityContext: { fsGroup: 1000 }, initContainers: [{ name: "permissions", image: entraImage, securityContext: { runAsUser: 0 }, command: ["chown", "1000:1000", "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/app/data"], volumeMounts: [{ name: "data", mountPath: "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/app/data" }] }] })); + resources.push(identity("lowkey-vault"), { apiVersion: "v1", kind: "Service", metadata: { name: "lowkey-vault", namespace }, spec: { selector: { app: "lowkey-vault" }, ports: [{ name: "https", port: 8443 }, { name: "identity", port: 8080 }] } }, deployment("lowkey-vault", "nagyesta/lowkey-vault:7.2.0-ubi10-minimal", { env: [{ name: "SERVER_SSL_KEY_STORE", value: "file:/certs/lowkey.p12" }, { name: "SERVER_SSL_KEY_STORE_PASSWORD", value: "scope-local-development" }, { name: "LOWKEY_ARGS", value: "--server.port=8443 --LOWKEY_VAULT_NAMES=- --LOWKEY_EXPORT_LOCATION=/data/export.json" }], volumeMounts: [...leafMounts, ...mount], readinessProbe: { tcpSocket: { port: 8443 }, periodSeconds: 5 } }, { volumes: [...leafVolumes, volume("lowkey-vault")] })); + for (const entry of runtimes) { + if (entry.kind === "rust") { + resources.push(identity(entry.name), service(entry.name, 18000), deployment(entry.name, `scope-local/${entry.name}:development`, { ports: [{ containerPort: 18000 }, { containerPort: 18897 }], readinessProbe: { tcpSocket: { port: 18897 }, periodSeconds: 5 } })); + continue; + } + resources.push(identity(entry.name)); + const image = `scope-local/${entry.dockerfile ? entry.name : "tools"}:development`; + if (entry.kind === "utility" || entry.kind === "tool") { + resources.push(job(entry.name, image, appCommand(entry), true)); + continue; + } + const port = entry.name === "portal" ? 5100 : 80; + const app = deployment(entry.name, image, { workingDir: "/app", command: appCommand(entry), envFrom: [{ configMapRef: { name: "scope-runtime" } }], env: [{ name: "PORT", value: String(port) }, { name: "NODE_EXTRA_CA_CERTS", value: "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/ca/rootCA.pem" }, { name: "SCHEDULER_TARGET_QUEUE_DEPTH", value: "1" }], ports: [{ containerPort: port }], volumeMounts: [{ name: "public-ca", mountPath: "/ca", readOnly: true }], ...(entry.kind === "service" ? { startupProbe: { tcpSocket: { port }, periodSeconds: 3, failureThreshold: 100 }, readinessProbe: entry.name === "api" ? { httpGet: { path: "/ready", port }, periodSeconds: 3 } : { tcpSocket: { port }, periodSeconds: 3 } } : {}) }, { volumes: [{ name: "public-ca", configMap: { name: "public-ca" } }] }); + if (entry.kind === "worker") (app.spec as Record).replicas = 0; + resources.push(service(entry.name, port), app); + } + resources.push(identity("dev-edge"), deployment("dev-edge", edgeImage, { volumeMounts: [...leafMounts, { name: "config", mountPath: "/etc/nginx/conf.d", readOnly: true }], readinessProbe: { tcpSocket: { port: 8080 }, periodSeconds: 3 } }, { volumes: [...leafVolumes, { name: "config", configMap: { name: "dev-edge" } }] })); + resources.push({ apiVersion: "v1", kind: "Service", metadata: { name: "dev-edge", namespace }, spec: { type: "NodePort", selector: { app: "dev-edge" }, ports: [{ name: "edge", port: 8080, targetPort: 8080, nodePort: 30080 }] } }); + for (const name of ["storage-init", "redirect-init", "db-migrate", "register-agents"]) { + resources.push(identity(name), job(name, "scope-local/tools:development", ["node", "--import", "tsx", "scripts/dev/bootstrap.ts", name])); + } + const entra = resources.find((resource) => resource.kind === "Deployment" && (resource.metadata as { name: string }).name === "entra-local"); + const entraSpec = entra!.spec as { template: { spec: { containers: { env: { name: string; value: string }[] }[] } } }; + entraSpec.template.spec.containers[0].env.push({ name: "TENANT_ID", value: config.tenant }); + const vault = resources.find((resource) => resource.kind === "Deployment" && (resource.metadata as { name: string }).name === "lowkey-vault"); + const vaultSpec = vault!.spec as { template: { spec: { securityContext?: unknown; initContainers?: unknown[]; containers: { command?: string[]; env: { name: string; value: string }[] }[] } } }; + const vaultPod = vaultSpec.template.spec; + vaultPod.securityContext = { runAsUser: 1000, runAsGroup: 1000, fsGroup: 1000 }; + vaultPod.initContainers = [{ name: "permissions", image: "nagyesta/lowkey-vault:7.2.0-ubi10-minimal", securityContext: { runAsUser: 0 }, command: ["chown", "1000:1000", "/data"], volumeMounts: mount }]; + const seed = JSON.stringify({ vaults: [{ attributes: { baseUri: "https://lowkey-vault:8443", recoveryLevel: "Recoverable+Purgeable", recoverableDays: 90, created: 0, deleted: null }, keys: {}, secrets: {}, certificates: {} }] }); + vaultPod.containers[0].command = ["/bin/sh", "-c", `[ -f /data/export.json ] || printf '%s\\n' '${seed}' > /data/export.json; exec java -jar /lowkey-vault.jar $LOWKEY_ARGS`]; + vaultPod.containers[0].env.find((value) => value.name === "LOWKEY_ARGS")!.value += " --LOWKEY_IMPORT_LOCATION=/data/export.json"; + const tag = env.SCOPE_IMAGE_TAG || "development"; + if (!/^[a-zA-Z\d_.-]+$/.test(tag)) throw new Error("Invalid SCOPE_IMAGE_TAG"); + return JSON.parse(JSON.stringify(resources).replaceAll(":development\"", `:${tag}\"`)) as Resource[]; +} + +if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { + const directory = resolve(process.argv[2] || ".dev-state/runtime/kustomize"); + mkdirSync(directory, { recursive: true }); + writeFileSync(resolve(directory, "resources.json"), JSON.stringify({ apiVersion: "v1", kind: "List", items: renderKindStack(process.argv.includes("--defaults") ? { AUTH_TENANT_ID: DEFAULT_TENANT } : process.env) }, null, 2)); + writeFileSync(resolve(directory, "kustomization.yaml"), "apiVersion: kustomize.config.k8s.io/v1beta1\nkind: Kustomization\nresources:\n - resources.json\n"); + console.log(`Generated ${directory}`); +} \ No newline at end of file diff --git a/scripts/dev/runtime.test.ts b/scripts/dev/runtime.test.ts new file mode 100644 index 000000000..64524b60c --- /dev/null +++ b/scripts/dev/runtime.test.ts @@ -0,0 +1,128 @@ +import { describe, expect, it } from "vitest"; +import { browserSettings, resolveRuntimeEnv } from "./config.js"; +import { runtimes, runtimeByName } from "./inventory.js"; +import { consumerEnvironment, launchCommand, startupState } from "./control.js"; +import { renderNativeWorkers } from "./workers.js"; +import { spawn } from "node:child_process"; + +describe("native container worker routing", () => { + it("preserves worker sidecars and removes duplicate backing services", () => { + const model = { services: { + "coder-acp-copilot": { depends_on: { api: {}, redis: {}, gateway: {}, "mcp-gateway-copilot": {} }, environment: { PROXY_BACKEND: "gateway" }, profiles: ["copilot"] }, + gateway: { depends_on: { redis: {} } }, + "mcp-gateway-copilot": {}, + api: {}, redis: {}, + } }; + const rendered = renderNativeWorkers(model, ["coder-acp-copilot"], {}, "scope-dev-test"); + expect(Object.keys(rendered.services).sort()).toEqual(["coder-acp-copilot", "gateway", "mcp-gateway-copilot"]); + expect(rendered.services["coder-acp-copilot"].environment).toMatchObject({ PROXY_BACKEND: "gateway", API_ENDPOINT: "http://host.docker.internal:3100", JUDGE_SERVICE_URL: "http://host.docker.internal:3101", REDIS_HOST: "redis" }); + expect(rendered.services["coder-acp-copilot"].ports).toEqual(["127.0.0.1:9240:9229"]); + expect(rendered.networks).toEqual({ default: { external: true, name: "scope-dev-test_default" } }); + expect(() => renderNativeWorkers(model, ["api"], {}, "test")).toThrow(/not a worker/); + }); +}); + +describe("lifecycle transitions", () => { + it("switches modes only after shutdown and discards old process ownership", () => { + const previous = { mode: "native" as const, active: true, restore: false, services: ["api"], processes: { api: { pid: 123, identity: "456" } } }; + expect(() => startupState(previous, "kind", undefined, false)).toThrow(/dev:down/); + expect(startupState({ ...previous, active: false }, "kind", undefined, true)).toMatchObject({ mode: "kind", phase: "starting", restore: true, processes: {} }); + }); + it("restores the selected services and rejects unknown services before bootstrap", () => { + const previous = startupState(undefined, "native", ["api"], true); + expect(startupState(previous, "native", undefined, true).services).toEqual(["api"]); + expect(startupState(previous, "native", ["portal"], false).services).toEqual(["portal"]); + expect(() => startupState(previous, "native", ["not-a-service"], false)).toThrow(/Unknown runtime/); + }); +}); + +describe("shared runtime configuration", () => { + it("uses worktree < local < process precedence without modifying inputs", () => { + const generated = { PUBLIC_ORIGIN: "https://generated.example.org", MONGODB_PORT: "27001" }; + const local = { PUBLIC_ORIGIN: "https://local.example.org" }; + const process = { PUBLIC_ORIGIN: "https://process.example.org" }; + const values = resolveRuntimeEnv({ generated, local, process }, "native"); + expect(values.PUBLIC_ORIGIN).toBe(process.PUBLIC_ORIGIN); + expect(values.MONGO_CONNECTION_STRING).toContain("127.0.0.1:27001"); + expect(values.MONGO_CONNECTION_STRING).toContain("directConnection=true"); + expect(local).toEqual({ PUBLIC_ORIGIN: "https://local.example.org" }); + }); + it.each(["compose", "kind"] as const)("keeps %s private DNS separate from the public issuer", (target) => { + const values = resolveRuntimeEnv({ process: { PUBLIC_ORIGIN: "https://dev.example.org" } }, target); + expect(values.MONGO_CONNECTION_STRING).toBe("mongodb://mongodb:27017/?replicaSet=rs0"); + expect(values.AUTH_JWKS_URI).toContain("https://entra-local:8443/"); + expect(values.AUTH_ISSUER_TEMPLATE).toBe("https://dev.example.org/{tenantid}/v2.0"); + expect(values.STORAGE_CONNECTION_STRING).toContain("http://azurite:10002/"); + }); + it("never forwards arbitrary Vite settings or credentials to the browser", () => { + const settings = browserSettings({ ...resolveRuntimeEnv({}, "native"), GITHUB_TOKEN: "secret", VITE_PROVIDER_KEY: "secret", NODE_TLS_REJECT_UNAUTHORIZED: "0" }); + expect(JSON.stringify(settings)).not.toContain("secret"); + expect(settings.VITE_AUTH_ENABLED_LOCAL).toBe("true"); + expect(settings).not.toHaveProperty("NODE_TLS_REJECT_UNAUTHORIZED"); + }); +}); + +describe("runtime inventory", () => { + it("pauses a real short-lived CLI process before allowing it to finish", async () => { + const entry = runtimeByName("cli"); + const [executable, ...args] = launchCommand(entry, true).map((argument) => argument.replace("--inspect-brk=127.0.0.1:9260", "--inspect-brk=127.0.0.1:0")); + const child = spawn(executable, args, { env: { ...consumerEnvironment(entry, { process: process.env }, resolveRuntimeEnv({}, "native")), CI: "true" }, stdio: ["ignore", "pipe", "pipe"] }); + let socket: WebSocket | undefined; + let output = ""; + child.stdout.on("data", (chunk: Buffer) => { output += chunk.toString(); }); + const exited = new Promise((resolvePromise, reject) => { child.once("exit", resolvePromise); child.once("error", reject); }); + try { + const inspector = await new Promise((resolvePromise, reject) => { + let errorOutput = ""; + child.stderr.on("data", (chunk: Buffer) => { + errorOutput += chunk.toString(); + const match = errorOutput.match(/ws:\/\/127\.0\.0\.1:\d+\/[a-f\d-]+/); + if (match) resolvePromise(match[0]); + }); + child.once("exit", () => reject(new Error("CLI exited before opening its inspector"))); + child.once("error", reject); + }); + socket = new WebSocket(inspector); + await new Promise((resolvePromise, reject) => { socket!.addEventListener("open", () => resolvePromise(), { once: true }); socket!.addEventListener("error", () => reject(new Error("Inspector connection failed")), { once: true }); }); + const paused = new Promise((resolvePromise) => { + socket!.addEventListener("message", (event) => { + const message: { method?: string; params?: { reason?: string } } = JSON.parse(String(event.data)); + if (message.method === "Debugger.paused") resolvePromise(message.params?.reason || ""); + }); + }); + socket.send(JSON.stringify({ id: 1, method: "Debugger.enable" })); + socket.send(JSON.stringify({ id: 2, method: "Runtime.runIfWaitingForDebugger" })); + expect(await paused).toBe("Break on start"); + socket.send(JSON.stringify({ id: 3, method: "Debugger.resume" })); + socket.close(); + expect(await exited).toBe(0); + expect(output).toContain("Usage:"); + } finally { + socket?.close(); + child.kill("SIGTERM"); + } + }, 20_000); + it("isolates consumer secrets and enables per-process break-on-start", () => { + const inputs = { process: { PATH: "/bin", GITHUB_TOKEN: "copilot-secret", ANTHROPIC_API_KEY: "anthropic-secret", NODE_OPTIONS: "--inspect=0.0.0.0:9229" } }; + const values = resolveRuntimeEnv({}, "native"); + const portal = consumerEnvironment(runtimeByName("portal"), inputs, values); + expect(portal).not.toHaveProperty("GITHUB_TOKEN"); + expect(portal).not.toHaveProperty("STORAGE_CONNECTION_STRING"); + expect(portal).not.toHaveProperty("NODE_OPTIONS"); + expect(consumerEnvironment(runtimeByName("coder-acp-copilot"), inputs, values).GITHUB_TOKEN).toBe("copilot-secret"); + expect(launchCommand(runtimeByName("cli"), true, ["--help"])).toContain("--inspect-brk=127.0.0.1:9260"); + }); + it("breaks before short-lived tool entrypoints without global inspector flags", () => { + expect(launchCommand(runtimeByName("tests"), true)).toContain("--inspect-brk=127.0.0.1:9262"); + expect(launchCommand(runtimeByName("db-migrations"), true).at(-1)).toBe("up"); + expect(launchCommand(runtimeByName("cli"), true).at(-1)).toBe("--help"); + expect(launchCommand(runtimeByName("db-migrations"), true, ["status"]).at(-1)).toBe("status"); + }); + it("allocates unique runtime identities and inspector ports", () => { + expect(new Set(runtimes.map((runtime) => runtime.name)).size).toBe(runtimes.length); + const ports = runtimes.flatMap((runtime) => runtime.inspector ? [runtime.inspector] : []); + expect(new Set(ports).size).toBe(ports.length); + expect(runtimeByName("post-processor").kind).toBe("worker"); + expect(() => runtimeByName("nonexistent")).toThrow(/Unknown runtime/); + }); +}); \ No newline at end of file diff --git a/scripts/dev/spike.test.ts b/scripts/dev/spike.test.ts new file mode 100644 index 000000000..2300a2310 --- /dev/null +++ b/scripts/dev/spike.test.ts @@ -0,0 +1,62 @@ +import { describe, expect, it, vi } from "vitest"; +import { registerRedirect, verifyMetadata, workspaceName } from "./spike.js"; +import { DEFAULT_TENANT } from "./config.js"; + +describe("spike resource isolation", () => { + it("scopes names deterministically to each workspace", () => { + expect(workspaceName("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/workspaces/first")).toMatch(/^scope-spike-[a-f\d]{12}$/); + expect(workspaceName("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/workspaces/first")).not.toBe(workspaceName("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/workspaces/second")); + expect(workspaceName("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/workspaces/first")).toBe(workspaceName("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/workspaces/first")); + }); +}); + +describe("exact redirect bootstrap", () => { + const pause = vi.fn(async () => {}); + it.each([201, 409])("accepts idempotent HTTP %s", async (status) => { + const send = vi.fn(async () => ({ status, body: {} })); + await registerRedirect(send, pause); + expect(send).toHaveBeenCalledTimes(1); + }); + it.each([400, 401, 403, 404])("does not retry HTTP %s", async (status) => { + const send = vi.fn(async () => ({ status, body: {} })); + await expect(registerRedirect(send, pause)).rejects.toThrow(`HTTP ${status}`); + expect(send).toHaveBeenCalledTimes(1); + }); + it("retries network and transient failures with bounded backoff", async () => { + const send = vi.fn().mockRejectedValueOnce(new Error("ECONNRESET")).mockResolvedValueOnce({ status: 503 }).mockResolvedValue({ status: 201 }); + const pause = vi.fn(async () => {}); + await registerRedirect(send, pause); + expect(send).toHaveBeenCalledTimes(3); + expect(pause.mock.calls).toEqual([[500], [1000]]); + }); + it("fails closed after five attempts", async () => { + const send = vi.fn(async () => ({ status: 503, body: {} })); + await expect(registerRedirect(send, pause)).rejects.toThrow(/five attempts/); + expect(send).toHaveBeenCalledTimes(5); + }); +}); + +describe("actual-image metadata acceptance", () => { + const origin = "https://example.app.github.dev"; + const issuer = `${origin}/${DEFAULT_TENANT}/v2.0`; + const discovery = { + issuer, + authorization_endpoint: `${origin}/${DEFAULT_TENANT}/oauth2/v2.0/authorize`, + token_endpoint: `${origin}/${DEFAULT_TENANT}/oauth2/v2.0/token`, + jwks_uri: `${origin}/${DEFAULT_TENANT}/discovery/v2.0/keys`, + end_session_endpoint: `${origin}/${DEFAULT_TENANT}/oauth2/v2.0/logout`, + userinfo_endpoint: `${origin}/graph/oidc/userinfo`, + }; + it("accepts matching discovery and key issuers", () => { + expect(() => verifyMetadata(discovery, { keys: [{ issuer }] }, origin, DEFAULT_TENANT)).not.toThrow(); + }); + it("rejects an internal hostname advertised to the browser", () => { + expect(() => verifyMetadata({ ...discovery, token_endpoint: "https://entra-local:8443/token" }, { keys: [{ issuer }] }, origin, DEFAULT_TENANT)).toThrow(/endpoint/); + }); + it.each([{ keys: [] }, { keys: [{ issuer: "https://wrong.example.org" }] }, { keys: [{}] }])("requires the external issuer on every JWK", (jwks) => { + expect(() => verifyMetadata(discovery, jwks, origin, DEFAULT_TENANT)).toThrow(/JWK/); + }); + it("rejects the wrong discovery issuer", () => { + expect(() => verifyMetadata({ ...discovery, issuer: "https://wrong.example.org" }, { keys: [{ issuer }] }, origin, DEFAULT_TENANT)).toThrow(/issuer/); + }); +}); \ No newline at end of file diff --git a/scripts/dev/spike.ts b/scripts/dev/spike.ts new file mode 100644 index 000000000..556036a91 --- /dev/null +++ b/scripts/dev/spike.ts @@ -0,0 +1,201 @@ +import { execFileSync } from "node:child_process"; +import { createHash } from "node:crypto"; +import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; +import { request } from "node:https"; +import { createServer } from "node:net"; +import { cpus, freemem, totalmem } from "node:os"; +import { resolve } from "node:path"; +import { setTimeout as delay } from "node:timers/promises"; +import { fileURLToPath } from "node:url"; +import { renderEdgeRoutes, resolveDevConfig } from "./config.js"; + +export const ENTRA_IMAGE = "ghcr.io/cmaneu/entra-local@sha256:70584ef110914d100409cb3d63a63548ccdde10ca780f9751755f1482dec5d7e"; + +/** Hash the workspace path so operations cannot address another worktree's state. */ +export function workspaceName(root: string): string { + return `scope-spike-${createHash("sha256").update(root).digest("hex").slice(0, 12)}`; +} + +interface JsonResponse { + status: number; + body: unknown; +} + +/** Retry bounded, idempotent bootstrap operations; reject permanent HTTP failures. */ +export async function registerRedirect(send: () => Promise, pause: (milliseconds: number) => Promise = delay): Promise { + for (let attempt = 0; attempt < 5; attempt++) { + let response: JsonResponse | undefined; + try { + response = await send(); + } catch (error) { + if (attempt === 4) throw error; + } + if (response?.status === 201 || response?.status === 409) return; + if (response && response.status !== 429 && response.status < 500) { + throw new Error(`Redirect registration rejected: HTTP ${response.status}`); + } + if (attempt === 4) throw new Error("Redirect registration exhausted five attempts"); + await pause(Math.min(500 * 2 ** attempt, 4000)); + } +} + +function record(value: unknown): Record { + if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Expected a JSON object"); + return value as Record; +} + +/** Verify discovery and every selected-key issuer without weakening API checks. */ +export function verifyMetadata(discovery: unknown, jwks: unknown, origin: string, tenant: string): void { + const metadata = record(discovery); + const issuer = `${origin}/${tenant}/v2.0`; + if (metadata.issuer !== issuer) throw new Error("Discovery issuer mismatch"); + for (const field of ["authorization_endpoint", "token_endpoint", "jwks_uri", "end_session_endpoint", "userinfo_endpoint"]) { + if (typeof metadata[field] !== "string" || new URL(metadata[field]).origin !== origin) { + throw new Error(`Unreachable/external discovery endpoint: ${field}`); + } + } + const keys = record(jwks).keys; + if (!Array.isArray(keys) || keys.length === 0 || !keys.every((key: unknown) => record(key).issuer === issuer)) { + throw new Error("Missing or inconsistent JWK issuer metadata"); + } +} + +function run(command: string, args: string[], env: NodeJS.ProcessEnv = process.env): void { + execFileSync(command, args, { stdio: "inherit", env, timeout: 300_000 }); +} + +function output(command: string, args: string[]): string { + return execFileSync(command, args, { encoding: "utf8", timeout: 30_000 }).trim(); +} + +/** Reserve the exact advertised port before starting, rather than silently shifting it. */ +async function assertFreePort(port: number): Promise { + await new Promise((resolvePromise, reject) => { + const server = createServer(); + server.once("error", () => reject(new Error(`Port ${port} is occupied; configure an explicit port override`))); + server.listen(port, "0.0.0.0", () => server.close((error) => error ? reject(error) : resolvePromise())); + }); +} + +async function main(): Promise { + const root = resolve(fileURLToPath(new URL("../..", import.meta.url))); + const state = resolve(root, ".dev-state/spike"); + const name = workspaceName(root); + const config = resolveDevConfig(process.env); + const entraPort = Number(process.env.SPIKE_ENTRA_PORT || "18443"); + if (!Number.isInteger(entraPort) || entraPort < 1024 || entraPort > 65535 || entraPort === config.edgePort) { + throw new Error("SPIKE_ENTRA_PORT must be a distinct port between 1024 and 65535"); + } + const certDir = resolve(state, "certs"); + const caDir = resolve(state, "authority"); + const edgeConfig = resolve(state, "edge.conf"); + const internalOrigin = `https://localhost:${entraPort}`; + const routes = renderEdgeRoutes(config, { + api: `http://localhost:${process.env.API_PORT || "3100"}`, portal: `http://localhost:${process.env.PORTAL_PORT || "5100"}`, entra: internalOrigin, + }); + const env = { + ...process.env, + ...config.auth, + AUTH_TENANT_ID: config.tenant, + SPIKE_ENTRA_PORT: String(entraPort), + SPIKE_CERT_DIR: certDir, + SPIKE_EDGE_CONFIG: edgeConfig, + COMPOSE_PARALLEL_LIMIT: "2", + CAROOT: caDir, + }; + const compose = (...args: string[]) => run("docker", ["compose", "--project-name", name, "--env-file", "/dev/null", "--file", resolve(root, ".devcontainer/spike/compose.yaml"), ...args], env); + const command = process.argv[2] || "doctor"; + + if (command === "doctor") { + console.log(`Phase-one spike only: ${name}\nOrigin: ${config.publicOrigin}\nTransport: ${config.codespaces ? "HTTP behind GitHub HTTPS" : "local HTTPS"}`); + console.log(`CPUs: ${cpus().length}; RAM: ${(totalmem() / 2 ** 30).toFixed(1)} GiB; free RAM: ${(freemem() / 2 ** 30).toFixed(1)} GiB`); + for (const [tool, args] of [["node", ["--version"]], ["pnpm", ["--version"]], ["mkcert", ["-version"]], ["kind", ["version"]], ["kubectl", ["version", "--client"]], ["docker", ["info", "--format", "{{.ServerVersion}}"]]] as const) { + try { console.log(`${tool}: ${output(tool, [...args])}`); } + catch { process.exitCode = 1; console.error(`UNAVAILABLE: ${tool}`); } + } + console.log(`Copilot process credential: ${process.env.GITHUB_TOKEN || process.env.GH_TOKEN ? "present, entitlement unverified" : "not supplied (stored token-manager credentials not inspected)"}`); + console.log(`Anthropic process credential: ${process.env.ANTHROPIC_API_KEY ? "present, entitlement unverified" : "not supplied"}`); + console.log(`Azure inference process credentials: ${process.env.AZURE_AI_INFERENCE_ENDPOINT && process.env.AZURE_AI_INFERENCE_API_KEY ? "present, entitlement unverified" : "not supplied"}`); + console.log("No provider calls are made; these checks do not prove live access."); + if (process.env.SCOPE_DIND_SPIKE !== "1") console.warn("DinD topology NOT VERIFIED: reopen in the provided privileged devcontainer before testing namespace/bind-mount assumptions."); + run("df", ["-h", root]); + return; + } + + if (command === "config") { + mkdirSync(state, { recursive: true, mode: 0o700 }); + writeFileSync(edgeConfig, routes); + writeFileSync(resolve(state, "public.json"), JSON.stringify({ ...config, auth: { ...config.auth, AUTH_JWKS_URI: `${internalOrigin}/${config.tenant}/discovery/v2.0/keys` } }, null, 2)); + console.log(`Generated non-secret settings in ${state}; .env and .env.local were not read or modified.`); + return; + } + + if (command === "down") { compose("down", "--remove-orphans", "--timeout", "20"); return; } + if (command === "logs") { compose("logs", "--tail", "100"); return; } + if (command === "reset-data") { + if (process.argv[3] !== `--confirm=${name}`) throw new Error(`Destructive reset requires --confirm=${name}; only this spike's emulator data and staged certificates will be removed`); + compose("down", "--volumes", "--remove-orphans", "--timeout", "20"); + return; + } + + if (command === "kind-up" || command === "kind-down") { + if (process.env.SCOPE_DIND_SPIKE !== "1") throw new Error("Kind spike requires reopening in the provided DinD devcontainer"); + mkdirSync(state, { recursive: true, mode: 0o700 }); + const kubeconfig = resolve(state, "kubeconfig"); + if (command === "kind-down") { run("kind", ["delete", "cluster", "--name", name, "--kubeconfig", kubeconfig]); return; } + await assertFreePort(8080); + run("kind", ["create", "cluster", "--name", name, "--kubeconfig", kubeconfig, "--config", resolve(root, ".devcontainer/kind/cluster.yaml"), "--wait", "120s"]); + run("kubectl", ["--kubeconfig", kubeconfig, "--context", `kind-${name}`, "get", "--raw", "/readyz"]); + console.log("Kind API ready. This spike deploys no application workloads; do not mark full-Kind acceptance complete."); + return; + } + + if (command !== "up" && command !== "probe") throw new Error("Usage: pnpm dev:spike doctor|config|up|probe|down|logs|reset-data|kind-up|kind-down"); + if (!existsSync(edgeConfig)) throw new Error("Run pnpm dev:spike config first"); + if (readFileSync(edgeConfig, "utf8") !== routes) throw new Error("Origin or port settings changed: stop the spike, regenerate config, and restart both dev-edge and Vite"); + if (command === "up") { + if (process.env.SCOPE_DIND_SPIKE !== "1") throw new Error("Spike startup requires reopening in the provided DinD devcontainer"); + await assertFreePort(config.edgePort); + await assertFreePort(entraPort); + mkdirSync(certDir, { recursive: true, mode: 0o700 }); + mkdirSync(caDir, { recursive: true, mode: 0o700 }); + run("mkcert", ["-cert-file", resolve(certDir, "edge.pem"), "-key-file", resolve(certDir, "edge-key.pem"), new URL(config.publicOrigin).hostname, "localhost", "entra-local"], env); + copyFileSync(resolve(caDir, "rootCA.pem"), resolve(certDir, "rootCA.pem")); + compose("up", "--detach", "--wait", "--wait-timeout", "120"); + } + + const ca = readFileSync(resolve(certDir, "rootCA.pem")); + const send = (path: string, body?: string): Promise => new Promise((resolvePromise, reject) => { + const req = request(`${internalOrigin}${path}`, { ca, method: body ? "POST" : "GET", headers: { "content-type": "application/json" }, timeout: 5000 }, (response) => { + let text = ""; + response.setEncoding("utf8"); + response.on("data", (chunk: string) => { text += chunk; }); + response.on("error", reject); + response.on("end", () => { + try { const parsed: unknown = JSON.parse(text); resolvePromise({ status: response.statusCode || 0, body: parsed }); } + catch (error) { reject(error); } + }); + }); + req.on("error", reject); + req.on("timeout", () => req.destroy(new Error("Entra request timed out"))); + req.end(body); + }); + await registerRedirect(() => send("/admin/api/apps/cccccccc-0000-0000-0000-000000000001/redirectUris", JSON.stringify({ uri: config.publicOrigin, type: "spa" }))); + const discovery = await send(`/${config.tenant}/v2.0/.well-known/openid-configuration`); + const jwks = await send(`/${config.tenant}/discovery/v2.0/keys`); + if (discovery.status !== 200 || jwks.status !== 200) throw new Error("Metadata endpoints are not ready"); + verifyMetadata(discovery.body, jwks.body, config.publicOrigin, config.tenant); + const curlArgs = ["--silent", "--show-error", "--max-time", "5", "--cacert", resolve(certDir, "rootCA.pem")]; + const edgeOrigin = `${config.codespaces ? "http" : "https"}://localhost:${config.edgePort}`; + const edgeDiscovery: unknown = JSON.parse(output("curl", [...curlArgs, "--fail", `${edgeOrigin}/${config.tenant}/v2.0/.well-known/openid-configuration`])); + verifyMetadata(edgeDiscovery, jwks.body, config.publicOrigin, config.tenant); + for (const path of ["/admin/api/apps", "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/graph/unknown", "/wrong-tenant/oauth2/v2.0/token"]) { + const status = output("curl", [...curlArgs, "--output", "/dev/null", "--write-out", "%{http_code}", `${edgeOrigin}${path}`]); + if (status !== "404") throw new Error(`dev-edge must deny ${path}, got HTTP ${status}`); + } + console.log(`Internal TLS, exact redirect registration, edge discovery, denied routes and JWK issuers verified.\nBrowser: ${config.publicOrigin}\nPKCE, logout allowlisting, API enrollment and private forwarding: STILL REQUIRE BROWSER VALIDATION.`); +} + +if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { + main().catch((error: unknown) => { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1; }); +} \ No newline at end of file diff --git a/scripts/dev/workers.ts b/scripts/dev/workers.ts new file mode 100644 index 000000000..c3d4f9bb6 --- /dev/null +++ b/scripts/dev/workers.ts @@ -0,0 +1,52 @@ +import { execFileSync } from "node:child_process"; +import { resolve } from "node:path"; +import { resolveRuntimeEnv, type RuntimeInputs } from "./config.js"; +import { runtimeByName } from "./inventory.js"; + +interface ComposeService { + environment?: Record; + depends_on?: Record; + volumes?: { type: string; source?: string }[]; + [key: string]: unknown; +} +interface ComposeModel { + services: Record; + volumes?: Record; +} + +/** Reuse the production worker/sidecar graph without starting duplicate native services. */ +export function renderNativeWorkers(model: ComposeModel, selected: string[], inputs: RuntimeInputs, project: string): ComposeModel & { networks: unknown } { + const allowed = new Set(["coder-acp-copilot", "coder-acp-claude-code", "report-generator", "post-processor", "gateway", "devproxy-claude-code", "devproxy-claude-code-init", "mcp-gateway-copilot", "mcp-gateway-claude-code", "register-version-post-processor"]); + const included = new Set(); + const visit = (name: string): void => { + if (included.has(name) || !allowed.has(name)) return; + const service = model.services[name]; + if (!service) throw new Error(`Missing existing worker dependency ${name}`); + included.add(name); + for (const dependency of Object.keys(service.depends_on || {})) visit(dependency); + }; + for (const name of selected) { + if (runtimeByName(name).kind !== "worker") throw new Error(`${name} is not a worker`); + visit(name); + } + const native = resolveRuntimeEnv(inputs, "native"); + const settings = resolveRuntimeEnv(inputs, "compose"); + for (const name of ["API_ENDPOINT", "SCOPE_MT_API_URL", "JUDGE_SERVICE_URL", "TOKEN_MANAGER_URL"]) settings[name] = native[name].replace("127.0.0.1", "host.docker.internal"); + const services = Object.fromEntries([...included].map((name) => { + const original = model.services[name]; + const service: ComposeService = { ...original, environment: { ...original.environment, ...settings }, depends_on: Object.fromEntries(Object.entries(original.depends_on || {}).filter(([dependency]) => included.has(dependency))), extra_hosts: ["host.docker.internal:host-gateway"], networks: ["default"] }; + for (const key of ["profiles", "ports", "develop", "container_name"]) delete service[key]; + const runtime = ["coder-acp-copilot", "coder-acp-claude-code", "report-generator", "post-processor"].includes(name) ? runtimeByName(name) : undefined; + if (runtime?.inspector) service.ports = [`127.0.0.1:${runtime.inspector}:9229`]; + return [name, service]; + })); + const usedVolumes = new Set(Object.values(services).flatMap((service) => (service.volumes || []).filter((volume) => volume.type === "volume" && volume.source).map((volume) => volume.source))); + return { services, volumes: Object.fromEntries(Object.entries(model.volumes || {}).filter(([name]) => usedVolumes.has(name))), networks: { default: { external: true, name: `${project}_default` } } }; +} + +export function existingWorkerModel(root: string, env: NodeJS.ProcessEnv): ComposeModel { + const source = execFileSync("docker", ["compose", "--env-file", "/dev/null", "--file", resolve(root, "docker-compose.yml"), "--file", resolve(root, "docker-compose.dev.yml"), "--profile", "*", "config", "--format", "json"], { env, encoding: "utf8", timeout: 30_000, maxBuffer: 8 * 1024 * 1024 }); + const model: ComposeModel = JSON.parse(source); + if (!model.services || typeof model.services !== "object") throw new Error("Invalid existing Compose worker model"); + return model; +} \ No newline at end of file diff --git a/website/src/content/docs/resources/contributing.md b/website/src/content/docs/resources/contributing.md index 4662aab1d..5ea80d4ae 100644 --- a/website/src/content/docs/resources/contributing.md +++ b/website/src/content/docs/resources/contributing.md @@ -22,6 +22,14 @@ and architecture references. Read [CONTRIBUTING.md](https://github.com/microsoft/scope/blob/main/CONTRIBUTING.md) for coding conventions, testing requirements, and the pull request process. +The checked-in devcontainer is an experimental DinD/Kind and authentication +topology probe, not a complete development stack. It requires a privileged, +disposable environment; real browser login and private Codespaces forwarding +remain unverified. See the +[spike instructions and evidence](https://github.com/microsoft/scope/blob/main/docs/architecture/devcontainer.md) +before using it. Continue to use the documented local-development workflow for +regular contributions. + ## Pull requests Open pull requests against `microsoft/scope` on `main`, including when working From e2826901156456456382e0cd8bfe4e19d2502e7f Mon Sep 17 00:00:00 2001 From: Christopher MANEU Date: Thu, 5 Nov 2026 16:40:43 +0000 Subject: [PATCH 2/8] fix(devcontainer): make Kind mode start and serve the Portal - mongo-init: mongosh --eval rejects await in loop bodies; use sleep() so the replica set initializes (idempotent on rerun) - dev-edge: keep proxy_set_header at server level so the public Host reaches Vite; a per-location header dropped it and Vite returned 403 - Deployments carry a scope.dev/config-hash annotation so ConfigMap changes roll exactly their consumers - Regenerate the committed Kind base manifests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .devcontainer/kind/base/resources.json | 44 +++++++++++++++++++++---- scripts/dev/config.test.ts | 7 ++++ scripts/dev/config.ts | 6 ++-- scripts/dev/kind.test.ts | 17 +++++++++- scripts/dev/kind.ts | 45 +++++++++++++++++++++++++- 5 files changed, 108 insertions(+), 11 deletions(-) diff --git a/.devcontainer/kind/base/resources.json b/.devcontainer/kind/base/resources.json index 2f3e9adc6..7ae12d6b6 100644 --- a/.devcontainer/kind/base/resources.json +++ b/.devcontainer/kind/base/resources.json @@ -63,7 +63,7 @@ "namespace": "scope-dev" }, "data": { - "default.conf": "map $http_upgrade $connection_upgrade {\n default upgrade;\n '' close;\n}\nserver {\n listen 8080 ssl;\n ssl_certificate /certs/edge.pem;\n ssl_certificate_key /certs/edge-key.pem;\n\n server_name localhost;\n client_max_body_size 100m;\n proxy_http_version 1.1;\n proxy_set_header Host localhost:8443;\n proxy_set_header X-Forwarded-Proto https;\n proxy_read_timeout 3600s;\n proxy_send_timeout 3600s;\n proxy_buffering off;\n proxy_ssl_verify on;\n proxy_ssl_trusted_certificate /ca/rootCA.pem;\n proxy_ssl_server_name on;\n location ~ ^/(?:api(?:/|$)|openapi\\.json$|api-docs(?:/|$)|health$|ready$|about$) {\n proxy_pass http://api:80;\n }\n location ~ ^/(?:11111111-1111-1111-1111-111111111111|common|organizations|consumers)/(?:v2\\.0/\\.well-known/openid-configuration$|discovery/v2\\.0/keys$|oauth2/v2\\.0(?:/|$)) {\n proxy_pass https://entra-local:8443;\n }\n location = /graph/oidc/userinfo {\n proxy_pass https://entra-local:8443;\n }\n location ~ ^/(?:admin(?:/|$)|graph(?:/|$)|(?:11111111-1111-1111-1111-111111111111|common|organizations|consumers)(?:/|$)|[^/]+/(?:v2\\.0|discovery|oauth2|openid)(?:/|$)) {\n return 404;\n }\n location / {\n proxy_set_header Upgrade $http_upgrade;\n proxy_set_header Connection $connection_upgrade;\n proxy_pass http://portal:5100;\n }\n}\n" + "default.conf": "map $http_upgrade $connection_upgrade {\n default upgrade;\n '' close;\n}\nserver {\n listen 8080 ssl;\n ssl_certificate /certs/edge.pem;\n ssl_certificate_key /certs/edge-key.pem;\n\n server_name localhost;\n client_max_body_size 100m;\n proxy_http_version 1.1;\n proxy_set_header Host localhost:8443;\n proxy_set_header X-Forwarded-Proto https;\n # Keep every header at server level: nginx drops all inherited proxy_set_header\n # directives in a location that declares any of its own.\n proxy_set_header Upgrade $http_upgrade;\n proxy_set_header Connection $connection_upgrade;\n proxy_read_timeout 3600s;\n proxy_send_timeout 3600s;\n proxy_buffering off;\n proxy_ssl_verify on;\n proxy_ssl_trusted_certificate /ca/rootCA.pem;\n proxy_ssl_server_name on;\n location ~ ^/(?:api(?:/|$)|openapi\\.json$|api-docs(?:/|$)|health$|ready$|about$) {\n proxy_pass http://api:80;\n }\n location ~ ^/(?:11111111-1111-1111-1111-111111111111|common|organizations|consumers)/(?:v2\\.0/\\.well-known/openid-configuration$|discovery/v2\\.0/keys$|oauth2/v2\\.0(?:/|$)) {\n proxy_pass https://entra-local:8443;\n }\n location = /graph/oidc/userinfo {\n proxy_pass https://entra-local:8443;\n }\n location ~ ^/(?:admin(?:/|$)|graph(?:/|$)|(?:11111111-1111-1111-1111-111111111111|common|organizations|consumers)(?:/|$)|[^/]+/(?:v2\\.0|discovery|oauth2|openid)(?:/|$)) {\n return 404;\n }\n location / {\n proxy_pass http://portal:5100;\n }\n}\n" } }, { @@ -460,7 +460,7 @@ "namespace": "scope-dev" }, "spec": { - "suspend": false, + "suspend": true, "backoffLimit": 2, "activeDeadlineSeconds": 600, "template": { @@ -484,7 +484,7 @@ "mongodb", "--quiet", "--eval", - "for(let attempt=0;attempt<90;attempt++){try{try{rs.status()}catch(error){if(error.code!==94)throw error;rs.initiate({_id:'rs0',members:[{_id:0,host:'mongodb:27017'}]})}if(db.hello().isWritablePrimary)quit(0)}catch(error){print(error.message)}await new Promise(resolve=>setTimeout(resolve,2000))}quit(1)" + "for (let attempt = 0; attempt < 90; attempt++) {\n try {\n try { rs.status() } catch (error) {\n if (error.code !== 94) throw error;\n rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: 'mongodb:27017' }] });\n }\n if (db.hello().isWritablePrimary) quit(0);\n } catch (error) { print(error.message) }\n sleep(2000);\n}\nquit(1);" ], "envFrom": [ { @@ -1105,6 +1105,9 @@ "metadata": { "labels": { "app": "api" + }, + "annotations": { + "scope.dev/config-hash": "b478df2f9d1172af" } }, "spec": { @@ -1244,6 +1247,9 @@ "metadata": { "labels": { "app": "portal" + }, + "annotations": { + "scope.dev/config-hash": "b478df2f9d1172af" } }, "spec": { @@ -1384,6 +1390,9 @@ "metadata": { "labels": { "app": "judge" + }, + "annotations": { + "scope.dev/config-hash": "b478df2f9d1172af" } }, "spec": { @@ -1522,6 +1531,9 @@ "metadata": { "labels": { "app": "token-manager" + }, + "annotations": { + "scope.dev/config-hash": "b478df2f9d1172af" } }, "spec": { @@ -1660,6 +1672,9 @@ "metadata": { "labels": { "app": "scheduler" + }, + "annotations": { + "scope.dev/config-hash": "b478df2f9d1172af" } }, "spec": { @@ -1886,6 +1901,9 @@ "metadata": { "labels": { "app": "coder-acp-copilot" + }, + "annotations": { + "scope.dev/config-hash": "b478df2f9d1172af" } }, "spec": { @@ -2010,6 +2028,9 @@ "metadata": { "labels": { "app": "coder-acp-claude-code" + }, + "annotations": { + "scope.dev/config-hash": "b478df2f9d1172af" } }, "spec": { @@ -2134,6 +2155,9 @@ "metadata": { "labels": { "app": "report-generator" + }, + "annotations": { + "scope.dev/config-hash": "b478df2f9d1172af" } }, "spec": { @@ -2258,6 +2282,9 @@ "metadata": { "labels": { "app": "post-processor" + }, + "annotations": { + "scope.dev/config-hash": "b478df2f9d1172af" } }, "spec": { @@ -3146,6 +3173,9 @@ "metadata": { "labels": { "app": "dev-edge" + }, + "annotations": { + "scope.dev/config-hash": "e75131b474f494d4" } }, "spec": { @@ -3255,7 +3285,7 @@ "namespace": "scope-dev" }, "spec": { - "suspend": false, + "suspend": true, "backoffLimit": 2, "activeDeadlineSeconds": 600, "template": { @@ -3325,7 +3355,7 @@ "namespace": "scope-dev" }, "spec": { - "suspend": false, + "suspend": true, "backoffLimit": 2, "activeDeadlineSeconds": 600, "template": { @@ -3395,7 +3425,7 @@ "namespace": "scope-dev" }, "spec": { - "suspend": false, + "suspend": true, "backoffLimit": 2, "activeDeadlineSeconds": 600, "template": { @@ -3465,7 +3495,7 @@ "namespace": "scope-dev" }, "spec": { - "suspend": false, + "suspend": true, "backoffLimit": 2, "activeDeadlineSeconds": 600, "template": { diff --git a/scripts/dev/config.test.ts b/scripts/dev/config.test.ts index aeb92d8b8..925b3140a 100644 --- a/scripts/dev/config.test.ts +++ b/scripts/dev/config.test.ts @@ -70,6 +70,13 @@ describe("dev-edge routing", () => { expect(routes).not.toContain("/auth/"); }); + it("never redeclares proxy headers inside a location, so the public Host is always forwarded", () => { + const locations = routes.split(/\n\s*location /).slice(1); + expect(locations.length).toBeGreaterThan(0); + for (const location of locations) expect(location).not.toContain("proxy_set_header"); + expect(routes).toContain("proxy_set_header Host localhost:8443;"); + }); + it("uses HTTP only behind Codespaces external HTTPS termination", () => { const remote = resolveDevConfig({ CODESPACES: "true", PUBLIC_ORIGIN: "https://example.app.github.dev" }); const routes = renderEdgeRoutes(remote, { api: "http://api:3000", portal: "http://portal:5100", entra: "https://entra-local:8443" }); diff --git a/scripts/dev/config.ts b/scripts/dev/config.ts index af6c1c5d6..b7f3ebff8 100644 --- a/scripts/dev/config.ts +++ b/scripts/dev/config.ts @@ -137,6 +137,10 @@ ${config.codespaces ? "" : " ssl_certificate /certs/edge.pem;\n ssl_certificat proxy_http_version 1.1; proxy_set_header Host ${new URL(config.publicOrigin).host}; proxy_set_header X-Forwarded-Proto https; + # Keep every header at server level: nginx drops all inherited proxy_set_header + # directives in a location that declares any of its own. + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; proxy_read_timeout 3600s; proxy_send_timeout 3600s; proxy_buffering off; @@ -156,8 +160,6 @@ ${config.codespaces ? "" : " ssl_certificate /certs/edge.pem;\n ssl_certificat return 404; } location / { - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection $connection_upgrade; proxy_pass ${upstreams.portal}; } } diff --git a/scripts/dev/kind.test.ts b/scripts/dev/kind.test.ts index f2124ce81..3d450be89 100644 --- a/scripts/dev/kind.test.ts +++ b/scripts/dev/kind.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { renderKindStack } from "./kind.js"; +import { MONGO_REPLICA_SET_INIT, renderKindStack } from "./kind.js"; import { runtimes } from "./inventory.js"; import { inspectorCommand } from "./cluster.js"; @@ -32,6 +32,21 @@ describe("complete Kind stack", () => { expect(text).toContain("--LOWKEY_IMPORT_LOCATION=/data/export.json"); expect(text).toContain('"runAsUser":1000'); }); + it("rolls ConfigMap consumers, and only them, when the public origin changes", () => { + const hashes = (origin: string): Record => Object.fromEntries(renderKindStack({ PUBLIC_ORIGIN: origin }).filter((resource) => resource.kind === "Deployment").map((resource) => [(resource.metadata as { name: string }).name, (resource.spec as { template: { metadata: { annotations?: Record } } }).template.metadata.annotations?.["scope.dev/config-hash"]])); + const before = hashes("https://localhost:8443"); + const after = hashes("https://scope.example.test:8443"); + for (const name of ["dev-edge", "api", "portal"]) { + expect(before[name]).toBeDefined(); + expect(after[name]).not.toBe(before[name]); + } + expect(before.mongodb).toBeUndefined(); + }); + it("keeps the replica-set bootstrap valid for mongosh --eval", () => { + expect(() => new Function(MONGO_REPLICA_SET_INIT)).not.toThrow(); + expect(MONGO_REPLICA_SET_INIT).not.toMatch(/\bawait\b/); + expect(text).toContain(JSON.stringify(MONGO_REPLICA_SET_INIT)); + }); it("keeps an overridden tenant and local TLS listener aligned with cluster routing", () => { const tenant = "22222222-2222-2222-2222-222222222222"; const local = JSON.stringify(renderKindStack({ AUTH_TENANT_ID: tenant })); diff --git a/scripts/dev/kind.ts b/scripts/dev/kind.ts index cf3d0aa4d..87a7d40f2 100644 --- a/scripts/dev/kind.ts +++ b/scripts/dev/kind.ts @@ -1,3 +1,4 @@ +import { createHash } from "node:crypto"; import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { resolve } from "node:path"; import { fileURLToPath } from "node:url"; @@ -9,6 +10,24 @@ export const namespace = "scope-dev"; const entraImage = "ghcr.io/cmaneu/entra-local@sha256:70584ef110914d100409cb3d63a63548ccdde10ca780f9751755f1482dec5d7e"; const edgeImage = "nginx@sha256:5b4900b042ccfa8b0a73df622c3a60f2322faeb2be800cbee5aa7b44d241649e"; +/** + * Idempotently initiate the single-member replica set and wait until it is writable. + * mongosh `--eval` rejects `await` inside loop bodies, so the retry pause uses its synchronous `sleep()`. + */ +export const MONGO_REPLICA_SET_INIT = [ + "for (let attempt = 0; attempt < 90; attempt++) {", + " try {", + " try { rs.status() } catch (error) {", + " if (error.code !== 94) throw error;", + " rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: 'mongodb:27017' }] });", + " }", + " if (db.hello().isWritablePrimary) quit(0);", + " } catch (error) { print(error.message) }", + " sleep(2000);", + "}", + "quit(1);", +].join("\n"); + function identity(name: string): Resource { return { apiVersion: "v1", kind: "ServiceAccount", metadata: { name, namespace }, automountServiceAccountToken: false }; } @@ -55,7 +74,7 @@ export function renderKindStack(env: NodeJS.ProcessEnv = {}): Resource[] { const volume = (name: string): Resource => ({ name: "data", persistentVolumeClaim: { claimName: name } }); const mount = [{ name: "data", mountPath: "/data" }]; resources.push(identity("mongodb"), service("mongodb", 27017), deployment("mongodb", "mongo:7.0.17", { command: ["mongod", "--replSet", "rs0", "--bind_ip_all", "--dbpath", "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/data/db"], volumeMounts: mount, readinessProbe: { exec: { command: ["mongosh", "--quiet", "--eval", "db.adminCommand({ping:1}).ok || quit(1)"] }, periodSeconds: 3 } }, { volumes: [volume("mongodb")] })); - resources.push(identity("mongo-init"), job("mongo-init", "mongo:7.0.17", ["mongosh", "--host", "mongodb", "--quiet", "--eval", "for(let attempt=0;attempt<90;attempt++){try{try{rs.status()}catch(error){if(error.code!==94)throw error;rs.initiate({_id:'rs0',members:[{_id:0,host:'mongodb:27017'}]})}if(db.hello().isWritablePrimary)quit(0)}catch(error){print(error.message)}await new Promise(resolve=>setTimeout(resolve,2000))}quit(1)"])); + resources.push(identity("mongo-init"), job("mongo-init", "mongo:7.0.17", ["mongosh", "--host", "mongodb", "--quiet", "--eval", MONGO_REPLICA_SET_INIT])); resources.push(identity("redis"), service("redis", 6379), deployment("redis", "redis:7.4.2-alpine", { command: ["redis-server", "--appendonly", "yes"], volumeMounts: mount, readinessProbe: { exec: { command: ["redis-cli", "ping"] }, periodSeconds: 3 } }, { volumes: [volume("redis")] })); resources.push(identity("azurite"), { apiVersion: "v1", kind: "Service", metadata: { name: "azurite", namespace }, spec: { selector: { app: "azurite" }, ports: [10000, 10001, 10002].map((port) => ({ name: `port-${port}`, port })) } }, deployment("azurite", "mcr.microsoft.com/azure-storage/azurite:3.29.0", { command: ["azurite", "--skipApiVersionCheck", "--loose", "--blobHost", "0.0.0.0", "--queueHost", "0.0.0.0", "--tableHost", "0.0.0.0", "--location", "/data"], volumeMounts: mount, readinessProbe: { tcpSocket: { port: 10001 }, periodSeconds: 3 } }, { volumes: [volume("azurite")] })); const leafVolumes = [{ name: "certificates", secret: { secretName: "development-certificates" } }, { name: "public-ca", configMap: { name: "public-ca" } }]; @@ -94,11 +113,35 @@ export function renderKindStack(env: NodeJS.ProcessEnv = {}): Resource[] { const seed = JSON.stringify({ vaults: [{ attributes: { baseUri: "https://lowkey-vault:8443", recoveryLevel: "Recoverable+Purgeable", recoverableDays: 90, created: 0, deleted: null }, keys: {}, secrets: {}, certificates: {} }] }); vaultPod.containers[0].command = ["/bin/sh", "-c", `[ -f /data/export.json ] || printf '%s\\n' '${seed}' > /data/export.json; exec java -jar /lowkey-vault.jar $LOWKEY_ARGS`]; vaultPod.containers[0].env.find((value) => value.name === "LOWKEY_ARGS")!.value += " --LOWKEY_IMPORT_LOCATION=/data/export.json"; + annotateConfigHashes(resources, { "scope-runtime": settings, "dev-edge": { "default.conf": edgeConfig } }); const tag = env.SCOPE_IMAGE_TAG || "development"; if (!/^[a-zA-Z\d_.-]+$/.test(tag)) throw new Error("Invalid SCOPE_IMAGE_TAG"); return JSON.parse(JSON.stringify(resources).replaceAll(":development\"", `:${tag}\"`)) as Resource[]; } +/** + * Stamp each Deployment's pod template with a hash of the ConfigMaps it consumes. + * ConfigMap edits (for example a new PUBLIC_ORIGIN) never restart pods on their own: + * env is read once at start and nginx does not reload mounted config. + * + * @param resources Rendered stack, mutated in place. + * @param configMaps ConfigMap name -> data, for every ConfigMap whose consumers must roll. + */ +function annotateConfigHashes(resources: Resource[], configMaps: Record>): void { + for (const resource of resources) { + if (resource.kind !== "Deployment") continue; + const template = (resource.spec as { template: { metadata: { annotations?: Record }; spec: unknown } }).template; + const podSpec = JSON.stringify(template.spec); + + // Hash only the ConfigMaps this pod references, so backing services do not restart needlessly. + const consumed = Object.keys(configMaps).filter((name) => podSpec.includes(`"name":"${name}"`)); + if (!consumed.length) continue; + const hash = createHash("sha256"); + for (const name of consumed) hash.update(name).update(JSON.stringify(configMaps[name])); + template.metadata.annotations = { ...template.metadata.annotations, "scope.dev/config-hash": hash.digest("hex").slice(0, 16) }; + } +} + if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { const directory = resolve(process.argv[2] || ".dev-state/runtime/kustomize"); mkdirSync(directory, { recursive: true }); From 7ff469dc9ff4f511287ffa71616f0c8c6700c1c0 Mon Sep 17 00:00:00 2001 From: Christopher MANEU Date: Thu, 5 Nov 2026 16:40:43 +0000 Subject: [PATCH 3/8] chore: remove unused k3d tooling The k3d:* scripts pointed to a missing scripts/k3d-up.sh. Remove them with the k3d config, build/teardown scripts and the k3d-only docker-bake.hcl. The devcontainer Kind mode is the local Kubernetes path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .k3d/config.yaml | 48 ------- docker-bake.hcl | 101 --------------- package.json | 10 +- scripts/k3d-build.sh | 291 ------------------------------------------- scripts/k3d-down.sh | 40 ------ 5 files changed, 1 insertion(+), 489 deletions(-) delete mode 100644 .k3d/config.yaml delete mode 100644 docker-bake.hcl delete mode 100755 scripts/k3d-build.sh delete mode 100755 scripts/k3d-down.sh diff --git a/.k3d/config.yaml b/.k3d/config.yaml deleted file mode 100644 index 5f02d5242..000000000 --- a/.k3d/config.yaml +++ /dev/null @@ -1,48 +0,0 @@ -# k3d Cluster Configuration for scope-core -# This configuration creates a lightweight Kubernetes cluster suitable for local development -# The bootstrap script will override the cluster name, registry name, and port mappings -# with worktree-specific values (e.g. scope-22, scope-22-registry.localhost) - -apiVersion: k3d.io/v1alpha5 -kind: Simple - -# Metadata section: defines the cluster identity -metadata: - name: scope-local # Default cluster name (bootstrap script will override with worktree-specific name) - -# Node configuration: defines the cluster topology -# This creates 1 control plane (server) node and 2 worker (agent) nodes -servers: 1 -agents: 2 - -# Kubernetes API server configuration -kubeAPI: - hostPort: "6443" # Port on host machine for API access (bootstrap script will override) - -# Port mappings: expose services from cluster to host machine -# These are mapped through the loadbalancer node filter -ports: - # Portal application service (NGINX frontend) - - port: 5100:30100 - nodeFilters: - - loadbalancer - # API service (backend) - - port: 3100:30200 - nodeFilters: - - loadbalancer - -# Registry configuration: built-in container registry for the cluster -registries: - create: - name: scope-registry.localhost - host: "0.0.0.0" - hostPort: "5050" - -# Additional options for k3s and k3d behavior -options: - k3s: - extraArgs: - # Disable Traefik ingress controller (we use custom ingress setup) - - arg: --disable=traefik - nodeFilters: - - server:* diff --git a/docker-bake.hcl b/docker-bake.hcl deleted file mode 100644 index 8e325dc28..000000000 --- a/docker-bake.hcl +++ /dev/null @@ -1,101 +0,0 @@ -# ============================================================================= -# docker-bake.hcl — Parallel image builds for k3d local development -# ============================================================================= -# Usage: -# docker buildx bake # Build all services in parallel -# docker buildx bake api # Build a single service -# docker buildx bake api portal judge # Build specific services -# -# Override registry: -# REGISTRY=my-registry:5050 docker buildx bake -# ============================================================================= - -variable "REGISTRY" { - default = "scope-0-registry.localhost:5050" -} - -# Worker version args — sourced from env (k3d-build.sh exports these from versions.env) -variable "COPILOT_CLI_VERSION" { - default = "" -} - -variable "CLAUDE_CODE_ACP_VERSION" { - default = "" -} - -variable "CLAUDE_AGENT_SDK_VERSION" { - default = "" -} - -group "default" { - targets = [ - "api", - "judge", - "portal", - "token-manager", - "scheduler", - "gateway", - "coder-acp-copilot", - "coder-acp-claude-code", - ] -} - -# --- Application services --- - -target "api" { - dockerfile = "apps/api/Dockerfile" - context = "." - tags = ["${REGISTRY}/scoped/api:latest"] -} - -target "judge" { - dockerfile = "apps/judge/Dockerfile" - context = "." - tags = ["${REGISTRY}/scoped/judge:latest"] -} - -target "portal" { - dockerfile = "apps/portal/Dockerfile" - context = "." - tags = ["${REGISTRY}/scoped/portal:latest"] -} - -target "token-manager" { - dockerfile = "apps/token-manager/Dockerfile" - context = "." - tags = ["${REGISTRY}/scoped/token-manager:latest"] -} - -target "scheduler" { - dockerfile = "apps/scheduler/Dockerfile" - context = "." - tags = ["${REGISTRY}/scoped/scheduler:latest"] -} - -target "gateway" { - dockerfile = "Dockerfile" - context = "apps/gateway" - target = "runtime" - tags = ["${REGISTRY}/scoped/gateway:latest"] -} - -# --- Worker services --- - -target "coder-acp-copilot" { - dockerfile = "apps/workers/coder-acp-copilot/Dockerfile" - context = "." - tags = ["${REGISTRY}/scoped/coder-acp-copilot:latest"] - args = { - COPILOT_CLI_VERSION = "${COPILOT_CLI_VERSION}" - } -} - -target "coder-acp-claude-code" { - dockerfile = "apps/workers/coder-acp-claude-code/Dockerfile" - context = "." - tags = ["${REGISTRY}/scoped/coder-acp-claude-code:latest"] - args = { - CLAUDE_CODE_ACP_VERSION = "${CLAUDE_CODE_ACP_VERSION}" - CLAUDE_AGENT_SDK_VERSION = "${CLAUDE_AGENT_SDK_VERSION}" - } -} diff --git a/package.json b/package.json index ee1abaf2e..103357bcd 100644 --- a/package.json +++ b/package.json @@ -88,15 +88,7 @@ "vscode-web:auto-auth-state": "pnpm --filter github-cookie-updater start", "worktrees:clean": "pnpm worktrees:clean:docker && pnpm worktrees:clean:worktrees", "worktrees:clean:worktrees": "tsx scripts/clean-worktrees.ts", - "worktrees:clean:docker": "tsx scripts/clean-compose.ts", - "k3d:up": "scripts/worktree-env.sh && ./scripts/k3d-up.sh", - "k3d:up:claude": "scripts/worktree-env.sh && ./scripts/k3d-up.sh --worker=claude", - "k3d:up:all": "scripts/worktree-env.sh && ./scripts/k3d-up.sh --worker=all", - "k3d:down": "scripts/worktree-env.sh && ./scripts/k3d-down.sh", - "k3d:build": "scripts/worktree-env.sh && ./scripts/k3d-build.sh", - "k3d:build:claude": "scripts/worktree-env.sh && ./scripts/k3d-build.sh --worker=claude", - "k3d:build:all": "scripts/worktree-env.sh && ./scripts/k3d-build.sh --worker=all", - "k3d:logs": "kubectl -n scoped logs -f --all-containers --prefix -l app.kubernetes.io/part-of=scoped --max-log-requests=20" + "worktrees:clean:docker": "tsx scripts/clean-compose.ts" }, "devDependencies": { "@d2t/vitest-ctrf-json-reporter": "^1.3.0", diff --git a/scripts/k3d-build.sh b/scripts/k3d-build.sh deleted file mode 100755 index 4517c53df..000000000 --- a/scripts/k3d-build.sh +++ /dev/null @@ -1,291 +0,0 @@ -#!/usr/bin/env bash -# ============================================================================= -# k3d-build.sh — Build and push Docker images to local k3d registry -# ============================================================================= -# Usage: -# ./scripts/k3d-build.sh # Build core + copilot worker (default) -# ./scripts/k3d-build.sh --worker=claude # Build core + claude worker -# ./scripts/k3d-build.sh --worker=all # Build core + all workers -# ./scripts/k3d-build.sh --worker=none # Build core services only (no workers) -# ./scripts/k3d-build.sh api # Build only the api -# ./scripts/k3d-build.sh api portal # Build api and portal -# ./scripts/k3d-build.sh --no-cache # Full rebuild without cache -# ============================================================================= -set -euo pipefail - -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" -cd "$REPO_ROOT" - -# Ensure Docker Desktop CLI tools are on PATH (OrbStack symlinks may be broken) -[ -d "/Applications/Docker.app/Contents/Resources/bin" ] \ - && export PATH="/Applications/Docker.app/Contents/Resources/bin:$PATH" - -# ── Detect container runtime ──────────────────────────────────────────────── -# Podman lacks `docker buildx` and its docker-compat push endpoint is unreliable, -# so podman builds/pushes with the native `podman` CLI instead. Override with -# CONTAINER_RUNTIME=podman|docker. (Capture `docker version` via command -# substitution — piping into `grep -q` trips SIGPIPE under `set -o pipefail`.) -if [ -z "${CONTAINER_RUNTIME:-}" ]; then - if command -v docker &>/dev/null; then - case "$(docker version 2>/dev/null || true)" in - *[Pp]odman*) CONTAINER_RUNTIME="podman" ;; - *) CONTAINER_RUNTIME="docker" ;; - esac - elif command -v podman &>/dev/null; then - CONTAINER_RUNTIME="podman" - else - CONTAINER_RUNTIME="docker" - fi -fi - -# Read port offset for registry port (env var takes precedence over file) -if [ -z "${PORT_OFFSET:-}" ]; then - PORT_OFFSET=0 - if [ -f ".port-offset" ]; then - PORT_OFFSET=$(cat .port-offset | tr -d '[:space:]') - fi -fi - -REGISTRY_PORT=$((5050 + PORT_OFFSET)) -REGISTRY="scope-${PORT_OFFSET}-registry.localhost:${REGISTRY_PORT}" - -# Ensure pushes to the local registry bypass any Docker/corporate proxy -export NO_PROXY="${NO_PROXY:+${NO_PROXY},}scope-${PORT_OFFSET}-registry.localhost,localhost,127.0.0.1" -export no_proxy="$NO_PROXY" - -# Parse flags -NO_CACHE="" -WORKER="copilot" -BUILD_TARGETS="" -for arg in "$@"; do - case "$arg" in - --no-cache) NO_CACHE="--no-cache" ;; - --worker=*) WORKER="${arg#--worker=}" ;; - *) BUILD_TARGETS="${BUILD_TARGETS:+$BUILD_TARGETS }$arg" ;; - esac -done - -# Core services (always built unless specific targets given) -CORE_SERVICES="api judge portal token-manager scheduler gateway" - -# Resolve worker list based on --worker flag -case "$WORKER" in - copilot) WORKER_SERVICES="coder-acp-copilot" ;; - claude) WORKER_SERVICES="coder-acp-claude-code" ;; - all) WORKER_SERVICES="coder-acp-copilot coder-acp-claude-code" ;; - none) WORKER_SERVICES="" ;; - *) echo "Error: Unknown worker '$WORKER'. Use: copilot, claude, all, none"; exit 1 ;; -esac - -# All known services (must match targets in docker-bake.hcl) -ALL_SERVICES="$CORE_SERVICES $WORKER_SERVICES" - -# Validate requested targets (check against all possible services) -VALID_SERVICES="api judge portal token-manager scheduler gateway coder-acp-copilot coder-acp-claude-code" -for svc in $BUILD_TARGETS; do - valid=false - for known in $VALID_SERVICES; do - if [ "$svc" = "$known" ]; then valid=true; break; fi - done - if [ "$valid" = "false" ]; then - echo "Error: Unknown service '$svc'" - echo "Available services: $VALID_SERVICES" - exit 1 - fi -done - -echo ">>> Building images → $REGISTRY" - -# ── Source worker version files as env vars for docker-bake.hcl ─────────── -for versions_file in apps/workers/*/versions.env apps/*/versions.env; do - if [ -f "$versions_file" ]; then - set -a - source "$versions_file" - set +a - fi -done - -# ── Podman: build + push with the native podman CLI ─────────────────────── -# Podman has no `docker buildx bake`, and pushing to the k3d HTTP registry via -# the docker-compat socket returns HTTP 500. Instead build each image with -# `podman build` and push to the registry over localhost (which podman treats -# as insecure by default). Images land in repo path `scoped/`, which the -# in-cluster `k3d-:5000` mirror resolves for pod pulls. -if [ "$CONTAINER_RUNTIME" = "podman" ]; then - if [ -z "$BUILD_TARGETS" ]; then - PODMAN_BUILD_LIST="$ALL_SERVICES" - else - PODMAN_BUILD_LIST="$BUILD_TARGETS" - fi - - echo " Runtime: podman — sequential build + push → localhost:${REGISTRY_PORT}" - echo "" - - podman_build_push() { - local svc=$1 - local dockerfile context image - local target_args=() build_args=() - - case "$svc" in - gateway) dockerfile="apps/gateway/Dockerfile"; context="apps/gateway"; target_args=(--target runtime) ;; - coder-acp-*) dockerfile="apps/workers/${svc}/Dockerfile"; context="." ;; - *) dockerfile="apps/${svc}/Dockerfile"; context="." ;; - esac - - if [ ! -f "$dockerfile" ]; then - echo " ⚠ $svc: $dockerfile not found — skipping" - return 0 - fi - - case "$svc" in - coder-acp-copilot) - build_args=(--build-arg "COPILOT_CLI_VERSION=${COPILOT_CLI_VERSION:-}") ;; - coder-acp-claude-code) - build_args=(--build-arg "CLAUDE_CODE_ACP_VERSION=${CLAUDE_CODE_ACP_VERSION:-}" - --build-arg "CLAUDE_AGENT_SDK_VERSION=${CLAUDE_AGENT_SDK_VERSION:-}") ;; - esac - - # Push over localhost (insecure) but keep the repo path pods expect. - image="localhost:${REGISTRY_PORT}/scoped/${svc}:latest" - - echo " Building $svc..." - if ! podman build ${NO_CACHE} "${target_args[@]}" "${build_args[@]}" \ - -t "$image" -f "$dockerfile" "$context"; then - echo " ✗ $svc build FAILED" - return 1 - fi - if ! podman push --tls-verify=false "$image"; then - echo " ✗ $svc push FAILED" - return 1 - fi - echo " ✓ $svc (pushed)" - } - - BUILD_FAILED=0 - for svc in $PODMAN_BUILD_LIST; do - podman_build_push "$svc" || BUILD_FAILED=1 - done - - [ "$BUILD_FAILED" -eq 0 ] || { echo ""; echo " ⚠ One or more images failed to build/push."; exit 1; } - exit 0 -fi - -# ── Try parallel build with docker buildx bake ──────────────────────────── -# Uses the default "docker" driver so builds share the host network and can -# push to the local k3d HTTP registry without insecure-registry workarounds. -if docker buildx bake --help &>/dev/null; then - # Use default builder (docker driver) — it shares host network so it can - # resolve the k3d registry on localhost. The docker-container driver runs - # in its own container and cannot reach localhost registries. - docker buildx use default 2>/dev/null || true - - BAKE_ARGS=(--file docker-bake.hcl --load) - - if [ -n "$NO_CACHE" ]; then - BAKE_ARGS+=(--no-cache) - fi - - if [ -z "$BUILD_TARGETS" ]; then - echo " Services: ALL (parallel)" - REGISTRY="$REGISTRY" docker buildx bake "${BAKE_ARGS[@]}" - PUSH_LIST="$ALL_SERVICES" - else - echo " Services: $BUILD_TARGETS (parallel)" - REGISTRY="$REGISTRY" docker buildx bake "${BAKE_ARGS[@]}" $BUILD_TARGETS - PUSH_LIST="$BUILD_TARGETS" - fi - - # Push images to local registry with timeout; fall back to k3d image import - CLUSTER_NAME="scope-${PORT_OFFSET:-0}" - echo "" - echo ">>> Loading images into cluster '$CLUSTER_NAME'..." - for svc in $PUSH_LIST; do - image="${REGISTRY}/scoped/${svc}:latest" - # Try push with 30s timeout first (fast when Docker Desktop cooperates) - if timeout 60 docker push "$image" --quiet 2>/dev/null; then - echo " ✓ $svc (pushed)" - else - # Fall back to k3d image import (reliable, no registry needed) - k3d image import "$image" --cluster "$CLUSTER_NAME" 2>/dev/null \ - && echo " ✓ $svc (imported)" \ - || echo " ⚠ $svc FAILED" - fi - done - - exit 0 -fi - -# ── Fallback: sequential docker build + push ────────────────────────────── -echo " ⚠ docker buildx bake unavailable — falling back to sequential builds" -echo " Install BuildKit for faster parallel builds." -echo "" - -get_dockerfile() { - local name=$1 - case "$name" in - gateway) echo "apps/gateway/Dockerfile" ;; - coder-acp-*) echo "apps/workers/${name}/Dockerfile" ;; - *) echo "apps/${name}/Dockerfile" ;; - esac -} - -get_build_context() { - local name=$1 - case "$name" in - gateway) echo "apps/gateway" ;; - *) echo "." ;; - esac -} - -get_target() { - local name=$1 - case "$name" in - gateway) echo "runtime" ;; - *) echo "" ;; - esac -} - -build_and_push() { - local name=$1 - local dockerfile=$(get_dockerfile "$name") - local context=$(get_build_context "$name") - local target=$(get_target "$name") - local image="${REGISTRY}/scoped/${name}:latest" - - if [ ! -f "$dockerfile" ]; then - echo " Warning: Dockerfile not found at $dockerfile, skipping $name" - return 0 - fi - - local target_arg="" - if [ -n "$target" ]; then target_arg="--target $target"; fi - - echo " Building $name..." - if ! docker build --file "$dockerfile" --tag "$image" ${target_arg} ${NO_CACHE} --quiet "$context"; then - echo " ⚠ Build failed for $name — skipping" - return 0 - fi -} - -if [ -z "$BUILD_TARGETS" ]; then - BUILD_LIST="$ALL_SERVICES" -else - BUILD_LIST="$BUILD_TARGETS" -fi - -echo " Services: $BUILD_LIST (sequential)" -echo "" - -for svc in $BUILD_LIST; do - build_and_push "$svc" -done - -# Push all built images to registry -echo "" -echo ">>> Pushing images to $REGISTRY..." -for svc in $BUILD_LIST; do - echo " Pushing $svc..." - docker push "${REGISTRY}/scoped/${svc}:latest" --quiet -done -echo " ✓ All images pushed" diff --git a/scripts/k3d-down.sh b/scripts/k3d-down.sh deleted file mode 100755 index c37d82c18..000000000 --- a/scripts/k3d-down.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -# ============================================================================= -# k3d-down.sh — Tear down the local k3d cluster -# ============================================================================= -set -euo pipefail - -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" -cd "$REPO_ROOT" - -# Read port offset (env var takes precedence over file) -if [ -z "${PORT_OFFSET:-}" ]; then - PORT_OFFSET=0 - if [ -f ".port-offset" ]; then - PORT_OFFSET=$(cat .port-offset | tr -d '[:space:]') - fi -fi - -CLUSTER_NAME="scope-${PORT_OFFSET:-0}" -REGISTRY_NAME="scope-${PORT_OFFSET:-0}-registry.localhost" - -if ! k3d cluster list 2>/dev/null | grep -q "^$CLUSTER_NAME "; then - echo "Cluster '$CLUSTER_NAME' does not exist." - exit 0 -fi - -echo ">>> Deleting k3d cluster '$CLUSTER_NAME'..." -k3d cluster delete "$CLUSTER_NAME" - -# Clean up the per-offset registry container. On podman the registry is created -# separately and persists after cluster deletion, so remove it explicitly. k3d -# lists/creates it with a 'k3d-' prefix; try the prefixed name first. -if k3d registry list 2>/dev/null | grep -q "$REGISTRY_NAME"; then - echo ">>> Deleting registry 'k3d-${REGISTRY_NAME}'..." - k3d registry delete "k3d-${REGISTRY_NAME}" 2>/dev/null \ - || k3d registry delete "$REGISTRY_NAME" 2>/dev/null \ - || echo " ⚠ Could not delete registry (may already be gone)." -fi - -echo ">>> Cluster '$CLUSTER_NAME' deleted." From d9f57452313fa4fbb712735773e15ae7e55bee54 Mon Sep 17 00:00:00 2001 From: Christopher MANEU Date: Thu, 5 Nov 2026 16:40:43 +0000 Subject: [PATCH 4/8] docs: document devcontainer Kind mode and local run options - CONTRIBUTING: table comparing Compose, native, and devcontainer modes - devcontainer.md: Kind mode usage, debugging, identities, evidence (including working browser sign-in via the Codespaces forward) and remaining work - Align auth-rbac, kubedock, ENV_VARIABLES, AGENTS and website contributing Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- AGENTS.md | 2 +- CONTRIBUTING.md | 53 ++++-- ENV_VARIABLES.md | 12 +- docs/architecture/auth-rbac.md | 12 +- docs/architecture/devcontainer.md | 180 ++++++++++++++---- docs/architecture/kubedock.md | 9 +- .../content/docs/resources/contributing.md | 15 +- 7 files changed, 207 insertions(+), 76 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index fba2fbf0f..7d4471e7d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -276,7 +276,7 @@ not open the PR against the fork unless the user explicitly asks you to. | [docs/architecture/post-processing.md](docs/architecture/post-processing.md) | Post-processing pipeline, ATIF generation, handler extensibility | | [docs/architecture/observability.md](docs/architecture/observability.md) | Application telemetry, Azure Monitor OTel distro, custom worker metrics | | [docs/architecture/kubedock.md](docs/architecture/kubedock.md) | Kubedock sidecar, container access for agents, Kustomize Component toggle | -| [docs/architecture/devcontainer.md](docs/architecture/devcontainer.md) | Experimental DinD/Kind auth topology spike, evidence and remaining implementation gates | +| [docs/architecture/devcontainer.md](docs/architecture/devcontainer.md) | Experimental DinD devcontainer: auth spike, Kind mode (`dev:up --mode=kind`), debugging, identities, evidence and remaining gates | | [docs/research/realtime-data-flow.md](docs/research/realtime-data-flow.md) | SSE + Change Streams, Redis pub/sub, polling patterns | | [docs/research/delta-storage.md](docs/research/delta-storage.md) | Space-efficient storage of iteration snapshots | | [docs/shared-dev-infra.md](docs/shared-dev-infra.md) | Shared dev infrastructure (CosmosDB) setup and worktree isolation | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4323a1d6d..fc87d961e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,17 +58,48 @@ dependencies. ## Local development -### Experimental devcontainer spike - -The checked-in devcontainer currently provides only a phase-one DinD/Kind and -Entra/dev-edge feasibility probe, **not the full Scope stack**. It requires a -privileged, disposable outer container. See the -[spike instructions and evidence ledger](./docs/architecture/devcontainer.md) -before using `pnpm dev:spike doctor`. Real local-browser and private-Codespaces -login remain unverified; use the existing Compose workflow below for regular -development. Never transfer a development CA private key to the browser host. - -### Existing Compose workflow +### Choose how to run Scope + +| Option | Commands | Where it runs | Hot reload | Status | +| --- | --- | --- | --- | --- | +| **Docker Compose** | `pnpm docker:dev:copilot` or `pnpm docker:dev:all` | Docker on your machine | Yes (Compose watch, polling) | Recommended; see [Compose workflow](#compose-workflow) | +| **Native processes** | `pnpm docker:up:infra`, then `pnpm dev:api`, `pnpm dev:portal`, `pnpm dev:` | Apps on your machine, databases in Docker | Yes | Supported; see [Compose workflow](#compose-workflow) | +| **Devcontainer, native mode** | `pnpm dev:up --mode=native` | Inside the devcontainer | Yes | Experimental; not yet tested end to end | +| **Devcontainer, Kind mode** | `pnpm dev:up --mode=kind --services=api,portal` | Kind cluster inside the devcontainer | No (rebuild with `--build`) | Experimental; tested in Codespaces, including browser sign-in | + +Which to pick: + +- **Day-to-day work and running real benchmarks:** Docker Compose. It is the only + option that runs workers, which spend provider credits. +- **Working on a single service:** native processes, for the fastest reloads and + simplest debugging. +- **Kubernetes or ServiceAccount work:** the devcontainer in Kind mode, preferably + in GitHub Codespaces until it has been tried on local Docker. + +### Devcontainer (experimental) + +The devcontainer bundles the toolchain and its own Docker daemon (Docker-in-Docker), +so it needs only Docker and VS Code, but it must run as a **privileged container**. +It is not a security sandbox: use a disposable environment without sensitive +mounts or credentials. + +- Native mode runs the databases in the devcontainer's Docker and the API and + Portal as processes behind one HTTPS address. +- Kind mode runs the whole stack in a Kubernetes cluster with one ServiceAccount + per workload. The first start builds a large tools image (about 6.5 GB); later + starts take about five minutes. Workers are rendered but never started, and + only the API and Portal have been verified. +- In Codespaces, forward port 8080 as a **private** port, open the printed + `https://-8080.app.github.dev` URL, and sign in with + `alice@entralocal.dev` / `Password1!`. +- Docker Desktop, WSL2, macOS and local-browser sign-in have not been validated. + On WSL2, keep the repository on the Linux filesystem, not under `/mnt/c`. + +See [devcontainer.md](./docs/architecture/devcontainer.md) for the commands, +debugging, identities, evidence and remaining work. Never transfer a development +CA private key to the browser host. + +### Compose workflow Local authentication requires your browser to trust a development certificate. The Portal development scripts run `mkcert -install` to add a local certificate diff --git a/ENV_VARIABLES.md b/ENV_VARIABLES.md index 85111817a..7f2d6dae1 100644 --- a/ENV_VARIABLES.md +++ b/ENV_VARIABLES.md @@ -1024,16 +1024,18 @@ token. > `sha256:70584ef110914d100409cb3d63a63548ccdde10ca780f9751755f1482dec5d7e` > was probed with verified TLS and publishes the configured external issuer on > every JWK. Earlier warnings about missing metadata do not establish that this -> image is incompatible. The [devcontainer spike](docs/architecture/devcontainer.md) -> records the limited evidence; browser PKCE and Portal/API login remain unverified. +> image is incompatible. The [devcontainer](docs/architecture/devcontainer.md) +> records the evidence, including a working browser sign-in through the Codespaces +> forward in Kind mode. > Do not remove key-issuer checks to accommodate an incompatible emulator. -> **Experimental dev-edge inputs.** Only `pnpm dev:spike` consumes `PUBLIC_ORIGIN`, +> **Experimental dev-edge inputs.** Only the devcontainer commands (`pnpm dev:up`, +> `pnpm dev:spike`) consume `PUBLIC_ORIGIN`, > `EDGE_PORT` (Codespaces HTTP, 8080), `EDGE_TLS_PORT` (local HTTPS, 8443), and > `SPIKE_ENTRA_PORT` (private loopback TLS, 18443). Codespaces origins are resolved > from `CODESPACE_NAME` and `GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN` at runtime. -> Process environment overrides defaults; the spike does not read `.env.local` -> or generated `.env`. This is not yet a shared full-stack precedence contract. +> `pnpm dev:up` resolves process environment > `.env.local` > generated `.env` > +> defaults; `pnpm dev:spike` reads only the process environment. > **Local dev TLS.** Compose trusts the emulator's mkcert CA through a read-only > public-CA mount and `NODE_EXTRA_CA_CERTS`; the certificate covers the internal diff --git a/docs/architecture/auth-rbac.md b/docs/architecture/auth-rbac.md index 8e88da02e..ba42fcbb9 100644 --- a/docs/architecture/auth-rbac.md +++ b/docs/architecture/auth-rbac.md @@ -68,12 +68,12 @@ must be resolved with stakeholders before or during implementation. ## Current implementation -The experimental [DinD/Kind development spike](devcontainer.md) verifies Entra -Local 0.1.1's external discovery/JWK issuers through a private internal TLS -endpoint and dev-edge. It does not change this authentication boundary or prove -browser PKCE, API enrollment, cached reload, logout, or Codespaces forwarding. -Those remain explicit phase-one acceptance gates; no synthetic principal or -verification bypass is introduced. +The experimental [devcontainer](devcontainer.md) verifies Entra Local 0.1.1's +external discovery/JWK issuers through a private internal TLS endpoint and +dev-edge. In Kind mode, a real browser sign-in through the owner-private +Codespaces forward works; a local-browser sign-in has not been checked yet. The +devcontainer does not change this authentication boundary: no synthetic +principal or verification bypass is introduced. | Component | In this branch | Relevant files | |-----------|-------|----------------| diff --git a/docs/architecture/devcontainer.md b/docs/architecture/devcontainer.md index 14b384791..4c3990fcc 100644 --- a/docs/architecture/devcontainer.md +++ b/docs/architecture/devcontainer.md @@ -1,11 +1,12 @@ # Devcontainer and Kind feasibility spike -Status: **phase one is incomplete; phases two through six have not started**. -The checked-in devcontainer is an experimental topology/auth probe, not a -complete Scope development environment. The broader implementation remains gated -on real local-browser and owner-private Codespaces PKCE login, including the -Portal/API handshake. Source inspection and localhost HTTP probes are not that -evidence. Existing Compose, worktree offsets, and k3d commands are unchanged. +Status: **experimental**. The auth spike (phase one) and a working Kind mode +(`pnpm dev:up --mode=kind`, phase four core) exist and have been exercised end to +end in Codespaces (see [Kind mode](#kind-mode) and the +[evidence ledger](#evidence-ledger)). Real browser sign-in through the +owner-private Codespaces forward works; a local-browser login (host certificate +trust) has not been checked yet. The existing Compose and worktree-offset +workflows are unchanged. ## Prerequisites and isolation @@ -130,49 +131,127 @@ registrations and signing keys, not other projects or the CA directory. It does not remove a Kind cluster. Failed startup leaves state for diagnosis; use `logs` and `down`, not global Docker prune/reset commands. -## Kind boot only +## Kind mode -Stop the auth spike first; its Codespaces listener and Kind mapping both use -8080. The optional boot probe has no application manifests, PVCs or workers. +Kind mode runs the backing services, the selected applications, and the dev edge +inside a single-node Kind cluster created in the devcontainer's own Docker daemon. +Stop native mode or the auth spike first (`pnpm dev:down`); both use the edge port. ```bash -pnpm dev:spike kind-up -pnpm dev:spike kind-down +pnpm dev:up --mode=kind --services=api,portal --build # first run: builds and loads images +pnpm dev:up --mode=kind --services=api,portal # later runs: reuse loaded images +pnpm dev:debug --mode=kind --service=api # inspector on 127.0.0.1:9230 +pnpm dev:job --service=tests # run a suspended one-shot Job +pnpm dev:smoke --mode=kind # credential-free up -> checks -> down +pnpm dev:down # deletes only this workspace's cluster ``` -The single node maps NodePort 30080 to loopback 8080. No Service is installed by -the spike. Every client operation names the cluster context and -`.dev-state/spike/kubeconfig`; the default kubeconfig is untouched and the API -is never browser-forwarded. Kind deletion removes only this named cluster. -Persistent workload storage, ServiceAccounts/RBAC, Kubedock, and the full local -Kustomize stack remain phase-four work. No privileged kubeconfig or Docker/runtime -socket is mounted into application pods; none are deployed yet. +The browser reaches the stack through one origin. The node maps NodePort 30080 +to loopback `EDGE_PORT`, and the in-cluster nginx edge routes by path. + +```mermaid +flowchart LR + Browser[Browser at PUBLIC_ORIGIN] -->|Codespaces private forward / local TLS| Edge[dev-edge NodePort 30080] + Edge -->|/api, /health, /ready| API[api Deployment] + Edge -->|OIDC discovery, keys, oauth2| Entra[entra-local] + Edge -->|everything else, HMR| Portal[portal Vite Deployment] + API --> Mongo[(mongodb rs0)] + API --> Redis[(redis)] + API --> Azurite[(azurite)] + API -->|JWKS by private DNS| Entra +``` + +How `dev:up --mode=kind` proceeds ([cluster.ts](../../scripts/dev/cluster.ts)): + +1. Mint edge/Entra leaf certificates (via the spike) and the separate Lowkey Vault PKI. +2. Create (or reuse) cluster `scope-dev-` with its own kubeconfig in + `.dev-state/runtime/kubeconfig`; the default kubeconfig is never touched. +3. Build (`--build`) and `kind load` `scope-local/:` images. App images + use each Dockerfile's `dev` target; Portal and one-shot tools share + [runtime.Dockerfile](../../.devcontainer/runtime.Dockerfile). +4. Render the stack ([kind.ts](../../scripts/dev/kind.ts)) into + `.dev-state/runtime/kustomize`, upload certificates as a Secret/ConfigMap, and apply. +5. Run the suspended init Jobs in order: `mongo-init` → `storage-init` → + `redirect-init` → `db-migrate`; then scale the selected Deployments to one replica + and run `register-agents` when the API is selected. + +Rendering rules that matter when you change the stack: + +- **Every workload has its own ServiceAccount** with `automountServiceAccountToken: false`. + No runtime socket, developer kubeconfig, or privileged identity is mounted. +- **Every Job renders `suspend: true`**; the lifecycle unsuspends init Jobs, and + utilities (model scanners, version checkers, cookie updater) only run via `dev:job`. + Workers render with zero replicas; do not start them without intending to spend credits. +- **Deployments carry a `scope.dev/config-hash` annotation** for the ConfigMaps they + consume (`scope-runtime`, `dev-edge`). A changed origin or setting rolls exactly those + pods; ConfigMap edits alone never restart pods or reload nginx. +- **Edge `proxy_set_header` directives live at server level only.** nginx drops all + inherited headers in a location that declares any of its own. A per-location + header once dropped the public `Host`, and Vite rejected the request as `Host: portal`. +- The init script for `mongo-init` is run with `mongosh --eval`, which rejects `await` + inside loop bodies; it pauses with mongosh's synchronous `sleep()`. +- [.devcontainer/kind/base](../../.devcontainer/kind/base) is a committed render of the + defaults; CI fails on drift. Regenerate with + `pnpm exec tsx scripts/dev/kind.ts .devcontainer/kind/base --defaults`. + +State persists across `dev:down`/cluster recreation: PersistentVolumes use +`Retain` hostPaths under `SCOPE_DEV_DATA` (a devcontainer-scoped volume) mounted +into the node at `/scope-state`. + +### Debugging in Kind + +`dev:debug --mode=kind --service=` patches the Deployment to +`node --inspect-brk=0.0.0.0:` (dropping `--watch` and probes), port-forwards +the inspector to **loopback only**, and restores the original command and probes +on exit. Attach with the **Scope: Attach Kind Node (Private Tunnel)** launch +configuration, which maps `/app` to the workspace. Inspector ports are listed in +[inventory.ts](../../scripts/dev/inventory.ts). tsx emits some modules on a single +generated line, so set breakpoints through VS Code (source-mapped), not with raw +CDP line numbers. + +### Kubedock and task identities + +Set `SCOPE_DEV_KUBEDOCK=true` before `dev:up` to add the +[kubedock component](../../.devcontainer/kind/components/kubedock): a sidecar on the +coding-agent workers with a short-lived projected token, and a namespace-scoped +Role in `scope-dev-tasks` (baseline Pod Security). The worker identities can manage +pods only in `scope-dev-tasks`, cannot create pods in `scope-dev`, and cannot read +secrets. Task pods run as `kubedock-task` with no token. See +[kubedock.md](kubedock.md) for the production equivalent. + +### Spike-only Kind boot + +`pnpm dev:spike kind-up` / `kind-down` still create a bare node with no manifests, +using `.dev-state/spike/kubeconfig`. It is kept only for topology probes. ## Runtime inventory and remaining sequence -This is the reviewed coverage checklist for the later implementation, not a -claim that every target currently exists. +The inventory in [inventory.ts](../../scripts/dev/inventory.ts) drives native launch, +image builds, Kind rendering, and debugger ports. "Rendered" means a workload and +identity exist in the Kind stack. "Verified" means it ran in the evidence ledger. -| Category | Required targets | Spike coverage | +| Category | Required targets | Kind mode coverage | | --- | --- | --- | -| Backing services | Replica-set MongoDB, Redis, all Azurite APIs, Lowkey Vault, Entra Local | Entra only | -| Initialization | Certificates, replica set, migrations, blobs/queues, redirects, agents/versions | Certificates and exact redirects only | -| Applications | API, Portal, Judge, token-manager, scheduler, Rust gateway | Edge upstream slots only | -| Workers | Copilot, Claude Code, report-generator, post-processor; existing enabled proxy/MCP sidecars | None; do not start paid workloads | -| Utilities | Copilot/Anthropic scanners, checked-in version checkers, cookie updater | None; explicit commands/jobs required | -| Developer tools | CLI, migrations, Vitest, Storybook, prompt evals, separate Astro install, Python environment | Focused Vitest tests only | -| Libraries | Workspace dependencies built/watched in dependency order | Not provisioned | +| Backing services | Replica-set MongoDB, Redis, all Azurite APIs, Lowkey Vault, Entra Local | All rendered and verified ready | +| Initialization | Certificates, replica set, migrations, blobs/queues, redirects, agents/versions | All verified as Jobs | +| Applications | API, Portal, Judge, token-manager, scheduler, Rust gateway | All rendered; API and Portal verified | +| Workers | Copilot, Claude Code, report-generator, post-processor; existing enabled proxy/MCP sidecars | Rendered at zero replicas; Kubedock RBAC verified; not started (paid) | +| Utilities | Copilot/Anthropic scanners, checked-in version checkers, cookie updater | Rendered as suspended Jobs (`dev:job`); not run | +| Developer tools | CLI, migrations, Vitest, Storybook, prompt evals, separate Astro install, Python environment | Migrations verified; others rendered as suspended Jobs | +| Libraries | Workspace dependencies built/watched in dependency order | Built in the tools/app images; no in-cluster watch of packages | | Windows | Separate image/runtime, private tunnel, `C:/app` mapping, Windows CI | Existing Windows exception preserved | -After the real login gate: phase two supplies the full pinned toolchain and -lifecycle; phase three supplies replica-set infrastructure, native launch tasks, -container workers and host-gateway routes; phase four supplies all images, -Kustomize/Jobs, persisted Kind state and least-privilege identities/Kubedock; -phase five supplies runtime-wide debugging, supervised private tunnels and -validated Skaffold sync/rebuild; phase six supplies credential-free CI smoke, -opt-in trusted provider tests and the complete acceptance matrix. Proposed -`dev:doctor`, `dev:up --mode=...`, `dev:down`, and `dev:debug` commands are **not -implemented**; do not confuse them with `dev:spike`. +Remaining work, in order: + +1. **Local-browser login:** repeat the browser sign-in in a local devcontainer, with the + public dev CA imported into the host trust store. +2. Start and verify judge, token-manager, scheduler and gateway in Kind; run one + opt-in, trusted worker end to end (consumes credits). +3. Validate Skaffold sync/rebuild ([skaffold.yaml](../../.devcontainer/skaffold.yaml)), + HMR over the Codespaces `wss`/443 forward, SSE, and downloads. +4. Reduce the 6.5 GB tools image (it dominates `kind load` time) and pin Debian packages. +5. Credential-free Kind smoke in CI, arm64/Docker Desktop validation, and the full + acceptance matrix. ## Evidence ledger @@ -189,8 +268,27 @@ Observed on 2026-11-02, Linux amd64 Codespaces host, 8 CPUs, 31.3 GiB RAM, | Wrong-host TLS certificate | Rejected by curl with exit 60 | | Kind internal `/readyz` with scoped kubeconfig | Passed; node readiness reported 17 seconds, not total cold-start time | | Idle auth-only snapshot | Entra 51.15 MiB / 9.90% CPU; edge 8.434 MiB / 0.00% CPU; not a sustained/full-stack measurement | -| Real PKCE/refresh/logout, Portal POST enrollment/GET reload, invalid-token tests | **Not run; phase-one exit gate remains open** | -| Private forwarding, host-browser trust, HMR/SSE/downloads, full-stack/provider/debugger/RBAC/platform acceptance | **Not run** | +| Real PKCE/refresh/logout, Portal POST enrollment/GET reload | Not run in the spike; see the Kind-mode browser sign-in below | +| Private forwarding, host-browser trust, HMR/SSE/downloads, provider/platform acceptance | **Not run** | + +Kind mode, observed on 2026-11-03, Linux amd64 Codespaces host, 16 CPUs, +62 GiB RAM, 100 GiB free disk: + +| Check | Result | +| --- | --- | +| `scripts/dev` unit tests / tooling typecheck / committed manifest drift | 77 passed / passed / in sync | +| `dev:up --mode=kind --services=api,portal --build` | Passed after fixing the `mongo-init` script; `api` image 862 MB, `tools` image 6.47 GB | +| Init Jobs (`mongo-init`, `storage-init`, `redirect-init`, `db-migrate`, `register-agents`) | All completed; `mongo-init` rerun is idempotent | +| Edge routes on `127.0.0.1:8080` | `/`, `/runs`, `/@vite/client`, `/health`, `/ready`, OIDC discovery and keys 200; `/admin/*` 404 | +| Invalid IdP bearer on `/api/v1/users/me` | 401 `invalid_token` | +| Discovery issuer | External Codespaces origin, not an internal hostname | +| `dev:debug --mode=kind --service=api` | Paused at entry; source breakpoint in the `/ready` handler hit via an edge request; Deployment restored on exit | +| Workload identities | `api` runs as SA `api`, no token mounted, cannot list pods | +| Kubedock component RBAC | Worker SAs: create pods in `scope-dev-tasks` yes, in `scope-dev` no, secrets no; `api` SA no | +| `dev:smoke --mode=kind` (cached images, new cluster, up → checks → down) | Passed in 332 s; cluster deleted | +| Real browser sign-in via the owner-private Codespaces forward (2026-11-05, manual) | Works; signed in to the Portal through the edge | +| Local-browser sign-in with host-trusted dev CA | **Not run** | +| Judge/token-manager/scheduler/gateway, workers, Skaffold, data persistence across cluster recreation | **Not run** | Immutable references used: @@ -200,5 +298,5 @@ Immutable references used: - Kind node 1.32.2: `sha256:142f543559cc55d64e1ab9341df08e5ced84bd2e893736da8f51320f26f5950b` - DinD 4.1.3: feature digest/integrity in `.devcontainer/devcontainer-lock.json`. -No live-provider entitlement, cold full-stack build, sustained resource load, -debugger breakpoint, arm64, Docker Desktop, or Windows success is implied. \ No newline at end of file +No live-provider entitlement, sustained resource load, arm64, Docker Desktop, or +Windows success is implied. \ No newline at end of file diff --git a/docs/architecture/kubedock.md b/docs/architecture/kubedock.md index e4e6ba095..316b681b7 100644 --- a/docs/architecture/kubedock.md +++ b/docs/architecture/kubedock.md @@ -38,11 +38,10 @@ Kubedock gives coding agents the ability to run Docker commands (build, run, exe ## Feature Flag (Kustomize Component) -The component described below is a design contract, not a component supplied by -the experimental [Kind boot spike](devcontainer.md). That spike deploys no -workers or Kubedock resources. A self-contained local component, scoped RBAC, -projected tokens and representative Docker-operation tests are still required -before claiming Kind worker support. +The devcontainer's [Kind mode](devcontainer.md#kubedock-and-task-identities) +ships its own local copy of this component (`SCOPE_DEV_KUBEDOCK=true`). Its scoped +RBAC has been verified, but no worker has run Docker operations through it yet, +so Kind worker support is not claimed. Kubedock is deployed as a **Kustomize Component** that overlays opt into per environment. diff --git a/website/src/content/docs/resources/contributing.md b/website/src/content/docs/resources/contributing.md index 5ea80d4ae..c20a7e6fe 100644 --- a/website/src/content/docs/resources/contributing.md +++ b/website/src/content/docs/resources/contributing.md @@ -22,13 +22,14 @@ and architecture references. Read [CONTRIBUTING.md](https://github.com/microsoft/scope/blob/main/CONTRIBUTING.md) for coding conventions, testing requirements, and the pull request process. -The checked-in devcontainer is an experimental DinD/Kind and authentication -topology probe, not a complete development stack. It requires a privileged, -disposable environment; real browser login and private Codespaces forwarding -remain unverified. See the -[spike instructions and evidence](https://github.com/microsoft/scope/blob/main/docs/architecture/devcontainer.md) -before using it. Continue to use the documented local-development workflow for -regular contributions. +Several ways to run Scope locally are available: Docker Compose (recommended), +native processes, and an experimental devcontainer with native and Kind modes. +The devcontainer requires a privileged, disposable environment; its Kind mode has +been tested in GitHub Codespaces, including browser sign-in. See +[Choose how to run Scope](https://github.com/microsoft/scope/blob/main/CONTRIBUTING.md#choose-how-to-run-scope) +for a comparison and the +[devcontainer documentation](https://github.com/microsoft/scope/blob/main/docs/architecture/devcontainer.md) +for details. ## Pull requests From 8ca83a8fc0c314921c8823975687b5bc6f9ed765 Mon Sep 17 00:00:00 2001 From: Christopher MANEU Date: Thu, 5 Nov 2026 16:46:12 +0000 Subject: [PATCH 5/8] build(devcontainer): install git-lfs The clone's LFS pre-push hook aborts pushes when git-lfs is missing. Install it from Debian (same source as git) and register its filters system-wide. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .devcontainer/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 2ba74ad5b..d4d7c894a 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,10 +1,11 @@ FROM node:22.22.0-bookworm@sha256:20a424ecd1d2064a44e12fe287bf3dae443aab31dc5e0c0cb6c74bef9c78911c RUN apt-get update && apt-get install -y --no-install-recommends \ - ca-certificates curl git sudo openssl mkcert libnss3-tools iptables jq \ + ca-certificates curl git git-lfs sudo openssl mkcert libnss3-tools iptables jq \ build-essential pkg-config libssl-dev cmake clang lldb libclang-dev \ python3 python3-venv python3-pip xz-utils unzip chromium xvfb x11vnc novnc websockify \ && rm -rf /var/lib/apt/lists/* \ + && git lfs install --system --skip-repo \ && printf 'node ALL=(root) NOPASSWD:ALL\n' > /etc/sudoers.d/node \ && chmod 0440 /etc/sudoers.d/node From 403602eecea3ba9377e9f268a1216013d50ace8f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 8 Nov 2026 12:12:28 +0000 Subject: [PATCH 6/8] Warn on low disk before Kind builds Co-authored-by: cmaneu <790974+cmaneu@users.noreply.github.com> --- docs/architecture/devcontainer.md | 5 +++++ scripts/dev/control.ts | 21 +++++++++++++++++++++ scripts/dev/runtime.test.ts | 21 ++++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/docs/architecture/devcontainer.md b/docs/architecture/devcontainer.md index 4c3990fcc..044b96510 100644 --- a/docs/architecture/devcontainer.md +++ b/docs/architecture/devcontainer.md @@ -146,6 +146,11 @@ pnpm dev:smoke --mode=kind # credential-free up -> pnpm dev:down # deletes only this workspace's cluster ``` +When `--build` is used, startup checks available disk space and warns if less +than 10 GiB is free; the warning does not block the build. After a successful +Kind startup in Codespaces, forward the configured edge port (`EDGE_PORT`, +default `8080`) from the Ports panel to open the browser URL. + The browser reaches the stack through one origin. The node maps NodePort 30080 to loopback `EDGE_PORT`, and the in-cluster nginx edge routes by path. diff --git a/scripts/dev/control.ts b/scripts/dev/control.ts index 8ca015431..f471fc887 100644 --- a/scripts/dev/control.ts +++ b/scripts/dev/control.ts @@ -13,9 +13,23 @@ export const root = resolve(fileURLToPath(new URL("../..", import.meta.url))); export const stateDirectory = resolve(root, ".dev-state/runtime"); export const project = workspaceName(root).replace("spike", "dev"); +const MIN_BUILD_DISK_SPACE = 10 * 2 ** 30; + interface ManagedProcess { pid: number; identity: string } interface State { mode: "native" | "kind"; active: boolean; restore: boolean; services?: string[]; phase?: "starting" | "ready" | "failed"; processes: Record } +/** Warn when a requested image build has less than 10 GiB available. */ +export function buildDiskSpaceWarning(availableBytes: number): string | undefined { + if (availableBytes >= MIN_BUILD_DISK_SPACE) return undefined; + return "Less than 10 GiB of disk space is available; Kind image builds may fail."; +} + +/** Give Codespaces users the configured port-forwarding step after Kind startup. */ +export function codespacesForwardingTip(environment: NodeJS.ProcessEnv, port: number): string | undefined { + if (environment.CODESPACES !== "true") return undefined; + return `Codespaces: forward port ${port} in the Ports panel to access the Kind environment.`; +} + /** Preserve ownership on failure; an explicit down is required before changing modes. */ export function startupState(previous: State | undefined, mode: State["mode"], services: string[] | undefined, restore: boolean): State { if (previous?.active && previous.mode !== mode) throw new Error(`Mode ${previous.mode} is active; run dev:down before switching`); @@ -281,6 +295,11 @@ async function main(): Promise { const mode = option("mode") || "native"; if (mode !== "native" && mode !== "kind") throw new Error("Mode must be native or kind"); if (state?.active && state.mode !== mode) throw new Error(`Mode ${state.mode} is active; run dev:down before switching`); + if (mode === "kind" && process.argv.includes("--build")) { + const disk = statfsSync(root); + const warning = buildDiskSpaceWarning(disk.bavail * disk.bsize); + if (warning) console.warn(warning); + } const next = startupState(state, mode, option("services")?.split(","), process.argv.includes("--restore")); const lock = resolve(stateDirectory, "operation.lock"); try { mkdirSync(lock); } catch { throw new Error("Another lifecycle operation is active; inspect .dev-state/runtime/operation.lock"); } @@ -297,6 +316,8 @@ async function main(): Promise { cluster.startCluster(inputEnv, next.services!, process.argv.includes("--build")); next.phase = "ready"; saveState(next); + const tip = codespacesForwardingTip(inputEnv, config.edgePort); + if (tip) console.log(tip); return; } compose(env, "up", "--detach", "--wait", "--wait-timeout", "180", "mongodb", "redis", "azurite", "lowkey-vault"); diff --git a/scripts/dev/runtime.test.ts b/scripts/dev/runtime.test.ts index 64524b60c..7f05e20fc 100644 --- a/scripts/dev/runtime.test.ts +++ b/scripts/dev/runtime.test.ts @@ -1,7 +1,13 @@ import { describe, expect, it } from "vitest"; import { browserSettings, resolveRuntimeEnv } from "./config.js"; import { runtimes, runtimeByName } from "./inventory.js"; -import { consumerEnvironment, launchCommand, startupState } from "./control.js"; +import { + buildDiskSpaceWarning, + codespacesForwardingTip, + consumerEnvironment, + launchCommand, + startupState, +} from "./control.js"; import { renderNativeWorkers } from "./workers.js"; import { spawn } from "node:child_process"; @@ -36,6 +42,19 @@ describe("lifecycle transitions", () => { }); }); +describe("startup guidance", () => { + it("warns before builds only when available disk space is below 10 GiB", () => { + expect(buildDiskSpaceWarning(10 * 2 ** 30)).toBeUndefined(); + expect(buildDiskSpaceWarning(10 * 2 ** 30 - 1)).toMatch(/10 GiB/); + }); + + it("shows the port-forwarding tip only in Codespaces", () => { + expect(codespacesForwardingTip({ CODESPACES: "true" }, 8080)) + .toContain("forward port 8080"); + expect(codespacesForwardingTip({}, 8080)).toBeUndefined(); + }); +}); + describe("shared runtime configuration", () => { it("uses worktree < local < process precedence without modifying inputs", () => { const generated = { PUBLIC_ORIGIN: "https://generated.example.org", MONGODB_PORT: "27001" }; From 4bd5b0e4e83f723ebb27c2b0db3ac231e7e7d5eb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Nov 2026 15:47:29 +0000 Subject: [PATCH 7/8] Configure Codespaces resources and port forwarding Co-authored-by: manekinekko <1699357+manekinekko@users.noreply.github.com> --- .devcontainer/devcontainer.json | 2 ++ docs/architecture/devcontainer.md | 26 ++++++++++++++------------ scripts/dev/config.test.ts | 17 +++++++++++++++++ scripts/dev/control.ts | 8 -------- scripts/dev/runtime.test.ts | 7 ------- 5 files changed, 33 insertions(+), 27 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index fbfc22fb0..263041a12 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,6 +1,7 @@ { "name": "Scope development (DinD + native/Kind)", "build": { "dockerfile": "Dockerfile", "context": ".." }, + "hostRequirements": { "cpus": 8, "memory": "32gb", "storage": "64gb" }, "remoteUser": "node", "features": { "ghcr.io/devcontainers/features/docker-in-docker:4.1.3": { @@ -25,6 +26,7 @@ "postCreateCommand": "sudo -n chown node:node /home/node/.local/share/pnpm/store /home/node/.cargo /home/node/.scope-state && pnpm install --frozen-lockfile && pnpm exec tsx scripts/dev/control.ts create", "postStartCommand": "pnpm exec tsx scripts/dev/control.ts start", "postAttachCommand": "pnpm exec tsx scripts/dev/control.ts attach", + "forwardPorts": [8080], "portsAttributes": { "8080": { "label": "dev-edge (Codespaces HTTP transport)", "protocol": "http", "requireLocalPort": true, "onAutoForward": "notify" }, "8443": { "label": "dev-edge (local HTTPS)", "protocol": "https", "requireLocalPort": true, "onAutoForward": "ignore" }, diff --git a/docs/architecture/devcontainer.md b/docs/architecture/devcontainer.md index 044b96510..7f958e605 100644 --- a/docs/architecture/devcontainer.md +++ b/docs/architecture/devcontainer.md @@ -23,15 +23,17 @@ and Kind node images are digest-pinned. Debian packages are **not snapshot-pinne this is not the final reproducible toolchain. Node 24 selection, Rust, Python/uv, browsers, Azure/PowerShell, and the remaining phase-two tools are still pending. -Initial sizing **targets, not verified minimums**: 4 CPUs / 16 GB for fast mode; -8 CPUs / 32 GB and at least 80 GB available disk for full Kind. On Docker Desktop, -configure the same CPU/RAM allocations and sufficient disk capacity under -Settings -> Resources (or the WSL2 resource configuration on Windows). The spike -bounds Compose concurrency at two; it does not start any workers. Full-stack -build and worker concurrency limits and cold/steady-state measurements remain -required. arm64 and Windows/macOS have not been validated; do not assume that -all images run natively on arm64. Windows worker execution and image validation -remain separate Windows targets, not Linux/Kind capabilities. +Codespaces requests 8 CPUs, 32 GB RAM, and 64 GB storage through +`.devcontainer/devcontainer.json` for the full Kind workload. This is a minimum +machine specification, subject to the machine types allowed by the organization. +For fast mode on Docker Desktop, configure at least 4 CPUs / 16 GB RAM and +sufficient disk capacity under Settings -> Resources (or the WSL2 resource +configuration on Windows). The spike bounds Compose concurrency at two; it does +not start any workers. Full-stack build and worker concurrency limits and +cold/steady-state measurements remain required. arm64 and Windows/macOS have not +been validated; do not assume that all images run natively on arm64. Windows +worker execution and image validation remain separate Windows targets, not +Linux/Kind capabilities. ## Run the probe @@ -147,9 +149,9 @@ pnpm dev:down # deletes only this work ``` When `--build` is used, startup checks available disk space and warns if less -than 10 GiB is free; the warning does not block the build. After a successful -Kind startup in Codespaces, forward the configured edge port (`EDGE_PORT`, -default `8080`) from the Ports panel to open the browser URL. +than 10 GiB is free; the warning does not block the build. The devcontainer +configuration forwards port `8080` automatically, so Codespaces users do not +need to add a port mapping manually. The browser reaches the stack through one origin. The node maps NodePort 30080 to loopback `EDGE_PORT`, and the in-cluster nginx edge routes by path. diff --git a/scripts/dev/config.test.ts b/scripts/dev/config.test.ts index 925b3140a..090f37ebf 100644 --- a/scripts/dev/config.test.ts +++ b/scripts/dev/config.test.ts @@ -1,6 +1,23 @@ +import { readFileSync } from "node:fs"; import { describe, expect, it } from "vitest"; import { DEFAULT_TENANT, renderEdgeRoutes, resolveDevConfig } from "./config.js"; +describe("Codespaces devcontainer options", () => { + it("requests the Kind machine size and forwards the edge port", () => { + const devcontainer: { + forwardPorts?: number[]; + hostRequirements?: { cpus?: number; memory?: string; storage?: string }; + } = JSON.parse(readFileSync(new URL("../../.devcontainer/devcontainer.json", import.meta.url), "utf8")); + + expect(devcontainer.hostRequirements).toEqual({ + cpus: 8, + memory: "32gb", + storage: "64gb", + }); + expect(devcontainer.forwardPorts).toContain(8080); + }); +}); + describe("development origin contract", () => { it("resolves local TLS and preserves the external port in known authorities", () => { const config = resolveDevConfig({}); diff --git a/scripts/dev/control.ts b/scripts/dev/control.ts index f471fc887..6750c0d69 100644 --- a/scripts/dev/control.ts +++ b/scripts/dev/control.ts @@ -24,12 +24,6 @@ export function buildDiskSpaceWarning(availableBytes: number): string | undefine return "Less than 10 GiB of disk space is available; Kind image builds may fail."; } -/** Give Codespaces users the configured port-forwarding step after Kind startup. */ -export function codespacesForwardingTip(environment: NodeJS.ProcessEnv, port: number): string | undefined { - if (environment.CODESPACES !== "true") return undefined; - return `Codespaces: forward port ${port} in the Ports panel to access the Kind environment.`; -} - /** Preserve ownership on failure; an explicit down is required before changing modes. */ export function startupState(previous: State | undefined, mode: State["mode"], services: string[] | undefined, restore: boolean): State { if (previous?.active && previous.mode !== mode) throw new Error(`Mode ${previous.mode} is active; run dev:down before switching`); @@ -316,8 +310,6 @@ async function main(): Promise { cluster.startCluster(inputEnv, next.services!, process.argv.includes("--build")); next.phase = "ready"; saveState(next); - const tip = codespacesForwardingTip(inputEnv, config.edgePort); - if (tip) console.log(tip); return; } compose(env, "up", "--detach", "--wait", "--wait-timeout", "180", "mongodb", "redis", "azurite", "lowkey-vault"); diff --git a/scripts/dev/runtime.test.ts b/scripts/dev/runtime.test.ts index 7f05e20fc..48cf94ca1 100644 --- a/scripts/dev/runtime.test.ts +++ b/scripts/dev/runtime.test.ts @@ -3,7 +3,6 @@ import { browserSettings, resolveRuntimeEnv } from "./config.js"; import { runtimes, runtimeByName } from "./inventory.js"; import { buildDiskSpaceWarning, - codespacesForwardingTip, consumerEnvironment, launchCommand, startupState, @@ -47,12 +46,6 @@ describe("startup guidance", () => { expect(buildDiskSpaceWarning(10 * 2 ** 30)).toBeUndefined(); expect(buildDiskSpaceWarning(10 * 2 ** 30 - 1)).toMatch(/10 GiB/); }); - - it("shows the port-forwarding tip only in Codespaces", () => { - expect(codespacesForwardingTip({ CODESPACES: "true" }, 8080)) - .toContain("forward port 8080"); - expect(codespacesForwardingTip({}, 8080)).toBeUndefined(); - }); }); describe("shared runtime configuration", () => { From b55992c96d4be3ed05fd363adfc4e55552d3a59d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Nov 2026 08:59:43 +0000 Subject: [PATCH 8/8] Fix devcontainer workflow checks Co-authored-by: cmaneu <790974+cmaneu@users.noreply.github.com> --- .github/workflows/devcontainer.yml | 6 +++--- scripts/dev/acceptance.ts | 3 +++ scripts/dev/bootstrap.ts | 3 +++ scripts/dev/cluster.ts | 3 +++ scripts/dev/config.test.ts | 3 +++ scripts/dev/config.ts | 3 +++ scripts/dev/control.ts | 3 +++ scripts/dev/inventory.ts | 3 +++ scripts/dev/kind.test.ts | 3 +++ scripts/dev/kind.ts | 3 +++ scripts/dev/runtime.test.ts | 3 +++ scripts/dev/spike.test.ts | 3 +++ scripts/dev/spike.ts | 3 +++ scripts/dev/workers.ts | 3 +++ 14 files changed, 42 insertions(+), 3 deletions(-) diff --git a/.github/workflows/devcontainer.yml b/.github/workflows/devcontainer.yml index 5be327a2a..ae8c545b2 100644 --- a/.github/workflows/devcontainer.yml +++ b/.github/workflows/devcontainer.yml @@ -30,8 +30,8 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 15 steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 with: node-version: '22.22.0' - name: Install locked dependencies @@ -42,7 +42,7 @@ jobs: - name: Test configuration and lifecycle contracts run: pnpm exec vitest run scripts/dev - name: Typecheck development tooling - run: pnpm exec tsc --noEmit --target ES2022 --module ESNext --moduleResolution Bundler --types node --esModuleInterop --skipLibCheck --strict scripts/dev/*.ts + run: pnpm exec tsc --noEmit --target ES2022 --module ESNext --moduleResolution Bundler --typeRoots packages/shared/node_modules/@types --types node --esModuleInterop --skipLibCheck --strict scripts/dev/*.ts - name: Validate shell and native infrastructure env: DEV_CERT_DIR: /tmp/scope-public-validation-certificates diff --git a/scripts/dev/acceptance.ts b/scripts/dev/acceptance.ts index 0a489ccf6..fe3579bc8 100644 --- a/scripts/dev/acceptance.ts +++ b/scripts/dev/acceptance.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + import { existsSync, readFileSync } from "node:fs"; import { request } from "node:https"; import { resolve } from "node:path"; diff --git a/scripts/dev/bootstrap.ts b/scripts/dev/bootstrap.ts index 0fdf02b2e..b291c13df 100644 --- a/scripts/dev/bootstrap.ts +++ b/scripts/dev/bootstrap.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + import { execFileSync } from "node:child_process"; import { readFileSync } from "node:fs"; import { createRequire } from "node:module"; diff --git a/scripts/dev/cluster.ts b/scripts/dev/cluster.ts index 74f1fd781..51662d4c6 100644 --- a/scripts/dev/cluster.ts +++ b/scripts/dev/cluster.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + import { execFileSync, spawn } from "node:child_process"; import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { resolve } from "node:path"; diff --git a/scripts/dev/config.test.ts b/scripts/dev/config.test.ts index 090f37ebf..1ebab7837 100644 --- a/scripts/dev/config.test.ts +++ b/scripts/dev/config.test.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + import { readFileSync } from "node:fs"; import { describe, expect, it } from "vitest"; import { DEFAULT_TENANT, renderEdgeRoutes, resolveDevConfig } from "./config.js"; diff --git a/scripts/dev/config.ts b/scripts/dev/config.ts index b7f3ebff8..42b3b9bc5 100644 --- a/scripts/dev/config.ts +++ b/scripts/dev/config.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + import { isIP } from "node:net"; export const DEFAULT_TENANT = "11111111-1111-1111-1111-111111111111"; diff --git a/scripts/dev/control.ts b/scripts/dev/control.ts index 6750c0d69..4ae72721f 100644 --- a/scripts/dev/control.ts +++ b/scripts/dev/control.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + import { execFileSync, spawn } from "node:child_process"; import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, statfsSync, writeFileSync } from "node:fs"; import { cpus, totalmem } from "node:os"; diff --git a/scripts/dev/inventory.ts b/scripts/dev/inventory.ts index d03382e6d..2e294579e 100644 --- a/scripts/dev/inventory.ts +++ b/scripts/dev/inventory.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + export interface RuntimeEntry { name: string; directory: string; diff --git a/scripts/dev/kind.test.ts b/scripts/dev/kind.test.ts index 3d450be89..23eab68cf 100644 --- a/scripts/dev/kind.test.ts +++ b/scripts/dev/kind.test.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + import { describe, expect, it } from "vitest"; import { MONGO_REPLICA_SET_INIT, renderKindStack } from "./kind.js"; import { runtimes } from "./inventory.js"; diff --git a/scripts/dev/kind.ts b/scripts/dev/kind.ts index 87a7d40f2..2c7f9f71e 100644 --- a/scripts/dev/kind.ts +++ b/scripts/dev/kind.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + import { createHash } from "node:crypto"; import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { resolve } from "node:path"; diff --git a/scripts/dev/runtime.test.ts b/scripts/dev/runtime.test.ts index 48cf94ca1..b0dbb088b 100644 --- a/scripts/dev/runtime.test.ts +++ b/scripts/dev/runtime.test.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + import { describe, expect, it } from "vitest"; import { browserSettings, resolveRuntimeEnv } from "./config.js"; import { runtimes, runtimeByName } from "./inventory.js"; diff --git a/scripts/dev/spike.test.ts b/scripts/dev/spike.test.ts index 2300a2310..f6412d4c9 100644 --- a/scripts/dev/spike.test.ts +++ b/scripts/dev/spike.test.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + import { describe, expect, it, vi } from "vitest"; import { registerRedirect, verifyMetadata, workspaceName } from "./spike.js"; import { DEFAULT_TENANT } from "./config.js"; diff --git a/scripts/dev/spike.ts b/scripts/dev/spike.ts index 556036a91..86b50c3a1 100644 --- a/scripts/dev/spike.ts +++ b/scripts/dev/spike.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + import { execFileSync } from "node:child_process"; import { createHash } from "node:crypto"; import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; diff --git a/scripts/dev/workers.ts b/scripts/dev/workers.ts index c3d4f9bb6..3c11ac3ff 100644 --- a/scripts/dev/workers.ts +++ b/scripts/dev/workers.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + import { execFileSync } from "node:child_process"; import { resolve } from "node:path"; import { resolveRuntimeEnv, type RuntimeInputs } from "./config.js";