Usage examples
Copy-paste recipes for the things you actually do with env-sync Viewer. They assume you have
cloned the repo, run pnpm install && pnpm build, and created the schema and the two login roles
from Getting started.
The examples use two connection strings. Swap in your own host, database and passwords:
export COLLECTOR_DB=postgresql://env_sync_collector:<secret>@127.0.0.1:5432/env_sync_viewer
export VIEWER_DB=postgresql://env_sync_viewer_app:<secret>@127.0.0.1:5432/env_sync_viewer
1. Smoke run with no credentials
Fill the dashboard with demo data using the fake env-sync the test suite ships
(apps/collector/test/fake-bin/env-sync). It accepts only the collector's exact invocation shape,
enforces ENV_SYNC_ALLOWED_PLATFORMS like the real binary, and answers from files in the manifest
directory. It needs a secrets.manifest.yml there. A manifest with no targets is enough, because
then nothing can be refused.
mkdir -p /tmp/esv-demo && cd /tmp/esv-demo
printf 'services:\n api:\n source: app-secrets/acme/api\n' > secrets.manifest.yml
cat > fake-stdout <<'EOF'
{"schemaVersion":1,"generatedAt":"2026-09-28T10:00:00.000Z","env":"dev","services":{"api":{"targets":[
{"target":"vercel my-app","platform":"vercel","diffMode":"fingerprint","status":"ok","keys":[
{"key":"API_KEY","status":"MATCH","expectedFingerprint":"0123456789ab","actualFingerprint":"0123456789ab"},
{"key":"DB_URL","status":"DRIFT","expectedFingerprint":"0123456789ab","actualFingerprint":"ba9876543210"}]}]}}}
EOF
echo '[{"manifestDir": "/tmp/esv-demo", "env": "dev", "services": ["api"]}]' > inventory.json
cd - # back to the repo root
PATH="$PWD/apps/collector/test/fake-bin:$PATH" DATABASE_URL=$COLLECTOR_DB \
node apps/collector/dist/main.js /tmp/esv-demo/inventory.json
Expected output (the run id differs):
probe: ENV_SYNC_ALLOWED_PLATFORMS enforcement verified (P-a, P-b)
::warning::[/tmp/esv-demo] inventory entry has no platforms scope (not pre-flight output): env-sync runs without any platform credential
[/tmp/esv-demo] env: base=[...] scoped=[ENV_SYNC_ALLOWED_PLATFORMS]
success <run-id> /tmp/esv-demo diff --service api --env dev --format json
The warning is expected: this inventory did not come from the pre-flight, so the run gets no
platform credentials. If you leave out secrets.manifest.yml, the fake exits 1 and the run is
recorded as failed, which is also a useful thing to see on the dashboard.
2. Collect one real manifest
A real run needs a credential scope, and only the pre-flight can produce one. Run the pre-flight
against your own inventory and allowlist, then hand its output to the collector. RUNNER_TEMP
picks the output directory (it defaults to the OS temp dir).
mkdir -p /tmp/esv-real/manifests/orders /tmp/esv-real/out
cp /path/to/acme/orders/secrets.manifest.yml /tmp/esv-real/manifests/orders/
cat > /tmp/esv-real/inventory.json <<'EOF'
[{ "manifestDir": "manifests/orders", "env": "prod", "services": ["api"] }]
EOF
cat > /tmp/esv-real/inventory.allow.json <<'EOF'
[{ "repo": "orders", "service": "api", "platforms": ["caprover"],
"captainDomain": "captain.example.com", "source": "app-secrets/orders/api",
"appName": "orders-api" }]
EOF
RUNNER_TEMP=/tmp/esv-real/out pnpm --filter @env-sync-viewer/collector exec \
tsx scripts/preflight.ts /tmp/esv-real/inventory.json /tmp/esv-real/inventory.allow.json
# pre-flight: 1 entry kept, 0 dropped -> /tmp/esv-real/out/inventory.filtered.json
DATABASE_URL=$COLLECTOR_DB \
OP_SERVICE_ACCOUNT_TOKEN=<token> \
CAPROVER_ADMIN_PASSWORD=<password> CAPROVER_ALLOWED_DOMAINS=captain.example.com \
node apps/collector/dist/main.js /tmp/esv-real/out/inventory.filtered.json
This needs the real env-sync (0.5.0 or later) on PATH. Start with a disposable,
non-production manifest. CapRover is the only platform with a credential rule today, so it is the
only platform the pre-flight will pass. See Collector reference.
3. Add a service to the inventory
Every collected service needs three committed things. The first two gate the pre-flight (it drops the service if either is wrong); the third is a test fixture:
-
An entry in
apps/collector/inventory.json:{ "manifestDir": "../../manifests/orders", "env": "prod", "services": ["api", "worker"] } -
One exact record per service in
apps/collector/inventory.allow.json(same shape as above). The record'srepois the basename ofmanifestDir. -
A fixture copy of the repo's manifest under
apps/collector/test/fixtures/manifests/<repo>/.
In CI, the repo must also be fetched: add it to the list in apps/collector/scripts/fetch-manifests.sh.
List only (service, env) pairs that are actually deployed. Asking about one that is not just
produces a services[].error that is noise.
4. Read the latest drift with SQL
The viewer role can SELECT and nothing else, so it is safe for ad-hoc queries:
-- psql "$VIEWER_DB"
-- Latest snapshot per target
SELECT DISTINCT ON (s.service, s.env, s.target_platform, s.target_descriptor)
s.service, s.env, s.target_platform, s.target_descriptor, s.status,
r.completed_at, r.outcome
FROM env_sync.drift_snapshots s
JOIN env_sync.collector_runs r ON r.id = s.collector_run_id
ORDER BY s.service, s.env, s.target_platform, s.target_descriptor, r.completed_at DESC;
-- The last 20 runs, newest first
SELECT outcome, completed_at, error_summary
FROM env_sync.collector_runs ORDER BY completed_at DESC LIMIT 20;
-- Every key that is not a MATCH
SELECT s.service, s.env, s.target_descriptor, k.key, k.key_status
FROM env_sync.drift_snapshot_keys k
JOIN env_sync.drift_snapshots s ON s.id = k.snapshot_id
WHERE k.key_status <> 'MATCH';
Try an INSERT as the viewer, or a SELECT as the collector: both fail with
permission denied for table collector_runs. That is the database doing its job.
5. Read the results
Per key (drift_snapshot_keys.key_status, and what the dashboard shows):
key_status | Dashboard | Meaning |
|---|---|---|
MATCH | match | the platform value's fingerprint equals 1Password's |
DRIFT | drift | the fingerprints differ |
MISSING_FROM_1PASSWORD | missing | the key is not in the 1Password item |
PRESENCE_PRESENT/PRESENCE_MISSING | present/missing | presence-only target: the key is (or is not) set |
NON_DIFFABLE | unverifiable | the target cannot be compared |
Per run (collector_runs.outcome): success (trustworthy document, no errors), partial
(trustworthy document with service or target errors), failed (nothing trusted, no snapshots).
Drift is data, so a run full of DRIFT is still success.
Per target: stale. A target is stale when it has no status = 'ok' snapshot within
STALE_AFTER_HOURS (default 26). Silence is never shown as health: a dead collector turns every
target stale.
6. Run the pre-flight alone
Check an inventory against the allowlist without touching any credential or database:
pnpm --filter @env-sync-viewer/collector exec tsx scripts/preflight.ts \
[inventory.json] [inventory.allow.json]
With no arguments it checks the committed apps/collector/inventory.json and
inventory.allow.json, reading manifests from each entry's manifestDir. Each drop prints one
line, for example:
::error::pre-flight dropped orders/api: no allowlist record
pre-flight: 0 entries kept, 1 dropped -> /tmp/.../inventory.filtered.json
It exits 0 even when it drops services. It exits non-zero only if the inventory or allowlist
file cannot be read or parsed. Use tsx through the collector package: it is not a root
dependency, so a bare pnpm exec tsx at the repo root will not find it.