Skip to content

Commit 2e18063

Browse files
committed
fix: harden task env wrapper for doppler config selection
1 parent 21b2ff9 commit 2e18063

4 files changed

Lines changed: 36 additions & 33 deletions

File tree

‎Taskfile.yml‎

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ vars:
99
sh: nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo "4"
1010
PARALLEL_COUNT:
1111
sh: echo $(({{.CPU_COUNT}} * 2))
12-
TERO_ENV: '{{.TERO_ENV | default "local"}}'
13-
# Wrap commands with doppler for non-local environments.
14-
ENV_PREFIX:
15-
sh: |
16-
if [ "{{.TERO_ENV}}" = "local" ]; then
17-
echo ""
18-
else
19-
echo "doppler run -c {{.TERO_ENV}} --"
20-
fi
2112

2213
tasks:
2314
# ===========================================================================
@@ -121,6 +112,16 @@ tasks:
121112
desc: Validate build
122113
cmds:
123114
- go vet ./...
115+
- task: check:task-run-env
116+
117+
check:task-run-env:
118+
desc: Validate task run env wiring for local and prd
119+
cmds:
120+
- |
121+
RUN_CMD="$(TERO_ENV=prd task -n run 2>&1 | tail -n 1)"
122+
echo "$RUN_CMD" | rg './scripts/with-env.sh go run ./cmd/tero' >/dev/null
123+
rg 'env_name="\$\{TERO_ENV:-local\}"' ./scripts/with-env.sh >/dev/null
124+
rg 'exec doppler run -c "\$env_name" -- "\$@"' ./scripts/with-env.sh >/dev/null
124125
125126
# ===========================================================================
126127
# Testing
@@ -134,22 +135,22 @@ tasks:
134135
test:integration:
135136
desc: Run integration tests (TERO_ENV=dev|prd)
136137
cmds:
137-
- '{{.ENV_PREFIX}} gotestsum --format short-verbose -- -race -tags=integration -run "^TestIntegration_" ./...'
138+
- './scripts/with-env.sh gotestsum --format short-verbose -- -race -tags=integration -run "^TestIntegration_" ./...'
138139

139140
test:correctness:
140141
desc: Run correctness tests (TERO_ENV=dev|prd)
141142
cmds:
142-
- '{{.ENV_PREFIX}} gotestsum --format short-verbose -- -v -tags=correctness -run "^TestCorrectness_" ./...'
143+
- './scripts/with-env.sh gotestsum --format short-verbose -- -v -tags=correctness -run "^TestCorrectness_" ./...'
143144

144145
test:correctness:powersync-replay:
145146
desc: Run deterministic PowerSync fixture replay correctness test
146147
cmds:
147148
- |
148149
if [ -n "{{.FIXTURE}}" ]; then
149-
TERO_POWERSYNC_FIXTURE_PATH="{{.FIXTURE}}" {{.ENV_PREFIX}} gotestsum --format short-verbose -- \
150+
TERO_POWERSYNC_FIXTURE_PATH="{{.FIXTURE}}" ./scripts/with-env.sh gotestsum --format short-verbose -- \
150151
-v -tags=correctness -run "^TestCorrectness_PowerSync_ControllerFixtureReplayDeterministic$" ./internal/powersync/extension
151152
else
152-
{{.ENV_PREFIX}} gotestsum --format short-verbose -- \
153+
./scripts/with-env.sh gotestsum --format short-verbose -- \
153154
-v -tags=correctness -run "^TestCorrectness_PowerSync_ControllerFixtureReplayDeterministic$" ./internal/powersync/extension
154155
fi
155156
@@ -166,7 +167,7 @@ tasks:
166167
run:
167168
desc: Run tero (TERO_ENV=local|dev|prd)
168169
cmds:
169-
- "{{.ENV_PREFIX}} go run ./cmd/tero {{.CLI_ARGS}}"
170+
- "./scripts/with-env.sh go run ./cmd/tero {{.CLI_ARGS}}"
170171

171172
dev:
172173
desc: Generate code and build
@@ -177,22 +178,22 @@ tasks:
177178
auth:login:
178179
desc: Login to Tero (TERO_ENV=local|dev|prd)
179180
cmds:
180-
- "{{.ENV_PREFIX}} go run ./cmd/tero auth login"
181+
- "./scripts/with-env.sh go run ./cmd/tero auth login"
181182

182183
auth:token:
183184
desc: Print current access token (TERO_ENV=local|dev|prd)
184185
cmds:
185-
- "{{.ENV_PREFIX}} go run ./cmd/tero auth token"
186+
- "./scripts/with-env.sh go run ./cmd/tero auth token"
186187

187188
auth:status:
188189
desc: Show auth status (TERO_ENV=local|dev|prd)
189190
cmds:
190-
- "{{.ENV_PREFIX}} go run ./cmd/tero auth status"
191+
- "./scripts/with-env.sh go run ./cmd/tero auth status"
191192

192193
auth:switch:
193194
desc: Switch organization (TERO_ENV=local|dev|prd)
194195
cmds:
195-
- "{{.ENV_PREFIX}} go run ./cmd/tero auth switch {{.CLI_ARGS}}"
196+
- "./scripts/with-env.sh go run ./cmd/tero auth switch {{.CLI_ARGS}}"
196197

197198
internal:powersync:capture:
198199
desc: Capture raw PowerSync stream to NDJSON (TERO_ENV=dev|prd)
@@ -202,7 +203,7 @@ tasks:
202203
MAX_BYTES: '{{.MAX_BYTES | default "26214400"}}'
203204
cmds:
204205
- |
205-
CMD="{{.ENV_PREFIX}} go run ./cmd/tero internal powersync capture --output {{.OUTPUT}} --duration {{.DURATION}} --max-bytes {{.MAX_BYTES}}"
206+
CMD="./scripts/with-env.sh go run ./cmd/tero internal powersync capture --output {{.OUTPUT}} --duration {{.DURATION}} --max-bytes {{.MAX_BYTES}}"
206207
if [ -n "{{.ACCOUNT_ID}}" ]; then
207208
CMD="$CMD --account-id {{.ACCOUNT_ID}}"
208209
fi
@@ -216,7 +217,7 @@ tasks:
216217
echo "INPUT and OUTPUT are required"
217218
exit 1
218219
fi
219-
CMD="{{.ENV_PREFIX}} go run ./cmd/tero internal powersync sanitize-fixture --input {{.INPUT}} --output {{.OUTPUT}}"
220+
CMD="./scripts/with-env.sh go run ./cmd/tero internal powersync sanitize-fixture --input {{.INPUT}} --output {{.OUTPUT}}"
220221
if [ -n "{{.MAX_LINES}}" ]; then
221222
CMD="$CMD --max-lines {{.MAX_LINES}}"
222223
fi
@@ -229,12 +230,12 @@ tasks:
229230
admin:join-org:
230231
desc: Join a client organization (TERO_ENV=dev|prd)
231232
cmds:
232-
- "{{.ENV_PREFIX}} go run ./cmd/admin join-org {{.CLI_ARGS}}"
233+
- "./scripts/with-env.sh go run ./cmd/admin join-org {{.CLI_ARGS}}"
233234

234235
admin:leave-org:
235236
desc: Leave a client organization (TERO_ENV=dev|prd)
236237
cmds:
237-
- "{{.ENV_PREFIX}} go run ./cmd/admin leave-org {{.CLI_ARGS}}"
238+
- "./scripts/with-env.sh go run ./cmd/admin leave-org {{.CLI_ARGS}}"
238239

239240
# ===========================================================================
240241
# Dependencies

‎docs/architecture/data-flow.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ the sync stream.
8383
Multi-tenant correctness depends on scope discipline.
8484

8585
The app derives scoped clients rather than mutating shared global state.
86-
You can see this in `APIServices.WithAccountID(...)` and chat
86+
You can see this in `ServiceSet.WithAccountID(...)` and chat
8787
`WithAccountID(...)` usage.
8888

8989
On org/account switches, runtime is torn down, scope is cleared, and onboarding

‎scripts/with-env.sh‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
env_name="${TERO_ENV:-local}"
5+
if [ "$env_name" = "local" ]; then
6+
exec "$@"
7+
fi
8+
9+
exec doppler run -c "$env_name" -- "$@"

‎taskfiles/debug.yml‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@ version: "3"
22

33
vars:
44
DEBUG_ENV: '{{.DEBUG_ENV | default "dev"}}'
5-
ENV_PREFIX:
6-
sh: |
7-
if [ "{{.DEBUG_ENV}}" = "local" ]; then
8-
echo ""
9-
else
10-
echo "doppler run -c {{.DEBUG_ENV}} --"
11-
fi
125

136
tasks:
147
list:
@@ -44,7 +37,7 @@ tasks:
4437
desc: Run Tero in debug mode (defaults to TERO_ENV=dev)
4538
deps: [guard:non-prd]
4639
cmds:
47-
- "{{.ENV_PREFIX}} go run ./cmd/tero {{.CLI_ARGS}}"
40+
- "TERO_ENV={{.DEBUG_ENV}} ./scripts/with-env.sh go run ./cmd/tero {{.CLI_ARGS}}"
4841

4942
ui:smoke:
5043
desc: Fast UI safety suite for app/update/render paths
@@ -118,7 +111,7 @@ tasks:
118111
MAX_BYTES: '{{.MAX_BYTES | default "26214400"}}'
119112
cmds:
120113
- |
121-
CMD="{{.ENV_PREFIX}} go run ./cmd/tero internal powersync capture --output {{.OUTPUT}} --duration {{.DURATION}} --max-bytes {{.MAX_BYTES}}"
114+
CMD="TERO_ENV={{.DEBUG_ENV}} ./scripts/with-env.sh go run ./cmd/tero internal powersync capture --output {{.OUTPUT}} --duration {{.DURATION}} --max-bytes {{.MAX_BYTES}}"
122115
if [ -n "{{.ACCOUNT_ID}}" ]; then
123116
CMD="$CMD --account-id {{.ACCOUNT_ID}}"
124117
fi
@@ -133,7 +126,7 @@ tasks:
133126
echo "INPUT and OUTPUT are required"
134127
exit 1
135128
fi
136-
CMD="{{.ENV_PREFIX}} go run ./cmd/tero internal powersync sanitize-fixture --input {{.INPUT}} --output {{.OUTPUT}}"
129+
CMD="TERO_ENV={{.DEBUG_ENV}} ./scripts/with-env.sh go run ./cmd/tero internal powersync sanitize-fixture --input {{.INPUT}} --output {{.OUTPUT}}"
137130
if [ -n "{{.MAX_LINES}}" ]; then
138131
CMD="$CMD --max-lines {{.MAX_LINES}}"
139132
fi

0 commit comments

Comments
 (0)