Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(dev-env): strip MULTICA_TASK_ENV_FILE from local env and CLI tests (MUL-10065) (#11412)

Bohan Jiang7299f2c82d7d
diff --git a/scripts/dev-env.sh b/scripts/dev-env.sh
index 49b315c9a8..ee885af238 100755
--- a/scripts/dev-env.sh
+++ b/scripts/dev-env.sh
@@ -52,14 +52,17 @@ DEV_TMPDIR="${MULTICA_DEV_TMPDIR:-$HOME/.multica/dev-tmp}"
# silently outranks server_url in a saved profile config. Every long-lived child
# is launched without them, so a local daemon cannot authenticate its local
# token against the production API — which fails as a bare 401 and reads like a
-# product bug. PATH is never stripped: the daemon resolves agent CLI paths by
-# forking the login shell.
+# product bug. MULTICA_TASK_ENV_FILE goes too: a warm pooled session exports it,
+# and the CLI reloads MULTICA_TOKEN / MULTICA_TASK_ID from that file on every
+# start, replacing the local token with the task's production one. PATH is
+# never stripped: the daemon resolves agent CLI paths by forking the login
+# shell.
CLEAN_ENV=(env
-u MULTICA_SERVER_URL -u MULTICA_TOKEN -u MULTICA_WORKSPACE_ID
-u MULTICA_DAEMON_PORT -u MULTICA_AGENT_ID -u MULTICA_AGENT_NAME
-u MULTICA_TASK_ID -u MULTICA_TASK_SLOT
-u MULTICA_TASK_CONFIG_ROOT -u MULTICA_TASK_WORKSPACES_ROOT
- -u MULTICA_WORKSPACES_ROOT)
+ -u MULTICA_WORKSPACES_ROOT -u MULTICA_TASK_ENV_FILE)
# ---------------------------------------------------------------- output ----
diff --git a/scripts/dev-env.test.sh b/scripts/dev-env.test.sh
index 8b43a87228..972614ad5e 100644
--- a/scripts/dev-env.test.sh
+++ b/scripts/dev-env.test.sh
@@ -603,12 +603,16 @@ require_contains "$out" "make down C=daemon"
# Commands launched through env-exec must not inherit the daemon-task identity
# hints that make human/profile CLI commands reject --profile.
write_manifest "clean-env-903" "$root_dir" 903
+# MULTICA_TASK_ENV_FILE counts as identity: the CLI reloads the task's
+# production token from it, replacing the local one.
MULTICA_TASK_CONFIG_ROOT=/task/config \
MULTICA_TASK_WORKSPACES_ROOT=/task/workspaces \
MULTICA_WORKSPACES_ROOT=/owner/workspaces \
+MULTICA_TASK_ENV_FILE=/task/task-env.json \
dev_env exec clean-env-903 -- sh -c '
test -z "${MULTICA_TASK_CONFIG_ROOT:-}" &&
test -z "${MULTICA_TASK_WORKSPACES_ROOT:-}" &&
+ test -z "${MULTICA_TASK_ENV_FILE:-}" &&
test "$MULTICA_WORKSPACES_ROOT" = "$1" &&
test "$MULTICA_DEV_ENV" = clean-env-903
' _ "$MULTICA_DEV_WORKSPACES_PARENT/multica_workspaces_dev-dev-env-test-903" \
diff --git a/server/cmd/multica/cmd_auth_test.go b/server/cmd/multica/cmd_auth_test.go
index 310754544a..4c2cc81774 100644
--- a/server/cmd/multica/cmd_auth_test.go
+++ b/server/cmd/multica/cmd_auth_test.go
@@ -12,11 +12,16 @@ import (
"testing"
"github.com/multica-ai/multica/server/internal/testutil"
+ "github.com/multica-ai/multica/server/pkg/agent"
"github.com/spf13/cobra"
)
func TestMain(m *testing.M) {
- for _, key := range []string{
+ // A task shell exports the daemon's identity, and a warm pooled session
+ // also exports MULTICA_TASK_ENV_FILE. main() re-applies that file before
+ // every command, so a fixture token set by a test would be replaced by the
+ // live task token. Strip both, plus every key the file can deliver.
+ for _, key := range append([]string{
"MULTICA_AGENT_ID",
"MULTICA_TASK_ID",
"MULTICA_TOKEN",
@@ -26,9 +31,10 @@ func TestMain(m *testing.M) {
"MULTICA_TASK_CONFIG_ROOT",
"MULTICA_TASK_WORKSPACES_ROOT",
"MULTICA_AGENT_NAME",
+ agent.TaskEnvFileEnv,
devEnvHomeEnv,
devEnvNameEnv,
- } {
+ }, agent.TaskEnvVolatileKeys...) {
os.Unsetenv(key)
}