fix(chat): bind project ID through CLI chat + stage dispatch (issue #2)
Root cause: the 2026-09-28 controlled-projection hardening added the ErrUnboundControlledProject guard, and the server path got session project binding backfilled - but two paths missed: - CLI chat mode never called session.SetProjectID (only -project name) - coordinator handleAdvanceStage built StageRunRequest without ProjectID/UserID, so every stage-advance squad task was rejected Fixes: - handleChatMode gains projectID param (wired from -project-id flag); session binding follows the server convention - handleAdvanceStage passes parseDecimalID(UserCtx.Project/User.ID) - CLI chat tests get hermetic env (unreachable DB + ALLOW_IN_MEMORY) so local runs stop accidentally hitting the real dev DB on :5433 - stale test TestBindSessionProjectContext_KeepsExistingProjectID asserted the pre-fix 'switch does not propagate' bug; updated to assert switch propagation + bind no-overwrite Result: go test -short ./... = 75 packages, 0 failures (first time). Short tests promoted from report-only back into the required CI gate.
This commit is contained in:
@@ -130,6 +130,7 @@ func main() {
|
||||
*chatQuery,
|
||||
*workDirFlag,
|
||||
*project,
|
||||
*projectIDFlag,
|
||||
*customer,
|
||||
*device,
|
||||
*use,
|
||||
@@ -590,6 +591,7 @@ func handleChatMode(
|
||||
chatQuery string,
|
||||
workDir string,
|
||||
project string,
|
||||
projectID int64,
|
||||
customer string,
|
||||
device string,
|
||||
use string,
|
||||
@@ -665,6 +667,11 @@ func handleChatMode(
|
||||
engine := coordinator.NewCoordinatorEngine(stageflow.New(svc))
|
||||
session := chat.NewSession("cli_chat_sess", userCtx, rec, engine)
|
||||
session.CtxMgr = bizdev.Snapshot(svc).Ctx
|
||||
// 回填会话项目绑定(与服务端 handlers 一致):受控交付物任务按数字项目 ID
|
||||
// 入账,仅传名称会让 ADVANCE_STAGE 派发被 ErrUnboundControlledProject 拒绝。
|
||||
if projectID > 0 {
|
||||
session.SetProjectID(projectID)
|
||||
}
|
||||
|
||||
// 单次提问模式 (支持脚本与自动化测试)
|
||||
if chatQuery != "" {
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestBizdevCLIHelpAndRun(t *testing.T) {
|
||||
|
||||
func TestBizdevCLIListTasks(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
envContent := "ENV=test\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\nALLOW_IN_MEMORY=true\n"
|
||||
envContent := "ENV=test\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\nALLOW_IN_MEMORY=true\nCONTEXT_DB_HOST=127.0.0.1\nCONTEXT_DB_PORT=1\n"
|
||||
envPath := filepath.Join(tmpDir, ".env")
|
||||
if err := os.WriteFile(envPath, []byte(envContent), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -49,7 +49,7 @@ func TestBizdevCLIListTasks(t *testing.T) {
|
||||
|
||||
func TestBizdevCLIExecuteAndInspect(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
envContent := "ENV=test\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\nALLOW_IN_MEMORY=true\n"
|
||||
envContent := "ENV=test\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\nALLOW_IN_MEMORY=true\nCONTEXT_DB_HOST=127.0.0.1\nCONTEXT_DB_PORT=1\n"
|
||||
envPath := filepath.Join(tmpDir, ".env")
|
||||
_ = os.WriteFile(envPath, []byte(envContent), 0o644)
|
||||
|
||||
@@ -114,7 +114,7 @@ func TestBizdevCLIExecuteAndInspect(t *testing.T) {
|
||||
|
||||
func TestBizdevCLIStageExecution(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
envContent := "ENV=test\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\nALLOW_IN_MEMORY=true\n"
|
||||
envContent := "ENV=test\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\nALLOW_IN_MEMORY=true\nCONTEXT_DB_HOST=127.0.0.1\nCONTEXT_DB_PORT=1\n"
|
||||
envPath := filepath.Join(tmpDir, ".env")
|
||||
_ = os.WriteFile(envPath, []byte(envContent), 0o644)
|
||||
|
||||
@@ -158,7 +158,7 @@ func TestBizdevCLIStageExecution(t *testing.T) {
|
||||
|
||||
func TestBizdevCLIChatQueries(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
envContent := "ENV=test\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\nALLOW_IN_MEMORY=true\n"
|
||||
envContent := "ENV=test\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\nALLOW_IN_MEMORY=true\nCONTEXT_DB_HOST=127.0.0.1\nCONTEXT_DB_PORT=1\n"
|
||||
envPath := filepath.Join(tmpDir, ".env")
|
||||
_ = os.WriteFile(envPath, []byte(envContent), 0o644)
|
||||
|
||||
@@ -244,7 +244,7 @@ func TestBizdevCLIChatQueries(t *testing.T) {
|
||||
|
||||
func TestBizdevCLIThreeBranchQueries(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
envContent := "ENV=test\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\nALLOW_IN_MEMORY=true\n"
|
||||
envContent := "ENV=test\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\nALLOW_IN_MEMORY=true\nCONTEXT_DB_HOST=127.0.0.1\nCONTEXT_DB_PORT=1\n"
|
||||
envPath := filepath.Join(tmpDir, ".env")
|
||||
_ = os.WriteFile(envPath, []byte(envContent), 0o644)
|
||||
|
||||
@@ -345,7 +345,7 @@ func TestBizdevCLIThreeBranchQueries(t *testing.T) {
|
||||
|
||||
func TestBizdevCLIExecuteAdhocTask(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
envContent := "ENV=test\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\nALLOW_IN_MEMORY=true\n"
|
||||
envContent := "ENV=test\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\nALLOW_IN_MEMORY=true\nCONTEXT_DB_HOST=127.0.0.1\nCONTEXT_DB_PORT=1\n"
|
||||
envPath := filepath.Join(tmpDir, ".env")
|
||||
_ = os.WriteFile(envPath, []byte(envContent), 0o644)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user