fix(deploy): preserve legacy environment and diagnose prepared plans safely
The old initializer defaults HN_ENVIRONMENT to development, while migration validation required the literal production and combined database/platform prerequisites into one opaque error. Preserve supported environment identity namespaces without editing the live .env; still require PostgreSQL and fixed HTTPS/WSS endpoints for every existing-server migration. Match supported boolean spellings and report failing field names without credential values. Add read-only diagnose for an existing prepared plan so an earlier failed prepare can be reviewed without deleting or regenerating its keyring. Move future prerequisite validation before private directory/key generation. Validation: 253 passed, 3 skipped (real PostgreSQL unavailable), 30 existing warnings; 40 deployment-tool tests including 11 new compatibility/redaction cases. Python 3.7 syntax and staged diff checks pass. Actual ECS diagnosis must still confirm the current failing field; no live config or key changed.
This commit is contained in:
@@ -33,6 +33,8 @@ def scenario(tmp_path,monkeypatch):
|
||||
env = {"HN_ENVIRONMENT":"production","HN_DATABASE_URL":"postgresql://fake@postgres/fake",
|
||||
"HN_FEISHU_ENABLED":"true","HN_OAUTH_ENABLED":"true","HN_FEISHU_APP_ID":"cli_test",
|
||||
"HN_FEISHU_APP_SECRET":"synthetic-app-secret","HN_ADMIN_SECRET":"a"*40,"HN_INTERNAL_SECRET":"b"*40}
|
||||
env.update(HN_PUBLIC_URL="https://relay.example.test",HN_ROUTER_URL="wss://relay.example.test/device/ws",
|
||||
HN_FEISHU_API_BASE="https://work.example.test",HN_FEISHU_AUTHORIZE_URL="https://work.example.test/open-apis/authen/v1/index")
|
||||
base = {"services":{name:{"image":"old:tag","environment":{},"networks":{"backend":None},"volumes":[]}
|
||||
for name in [*roles,"postgres","redis"]},"volumes":{"metadata":{}},"networks":{"backend":{}}}
|
||||
base["services"]["connector"]["environment"] = env
|
||||
@@ -152,6 +154,50 @@ def test_prepare_refuses_existing_output_and_preserves_key(scenario):
|
||||
assert (scenario["output"]/"credential-keyring.json").read_bytes() == key
|
||||
|
||||
|
||||
@pytest.mark.parametrize("environment", ["development","test","production"])
|
||||
def test_preserves_existing_environment_namespace_with_tls(scenario,environment):
|
||||
scenario["base"]["services"]["connector"]["environment"]["HN_ENVIRONMENT"] = environment
|
||||
plan = prepared(scenario)
|
||||
deploy.check(scenario["output"],plan)
|
||||
merged = deploy.run(deploy.compose(plan,scenario["output"]/"compose.broker.json")+["config"],True)
|
||||
assert merged["services"]["connector"]["environment"]["HN_ENVIRONMENT"] == environment
|
||||
assert merged["services"]["router"]["environment"]["HN_ENVIRONMENT"] == environment
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name,value", [("HN_DATABASE_URL","sqlite://synthetic-secret"),
|
||||
("HN_ENVIRONMENT","invalid-private-value"),("HN_FEISHU_ENABLED","false"),
|
||||
("HN_PUBLIC_URL","http://synthetic-secret"),("HN_ROUTER_URL","ws://synthetic-secret"),
|
||||
("HN_FEISHU_API_BASE","http://synthetic-secret")])
|
||||
def test_prerequisite_failure_reports_field_before_generating_keys(scenario,name,value):
|
||||
scenario["base"]["services"]["connector"]["environment"][name] = value
|
||||
with pytest.raises(deploy.DeployError) as error:
|
||||
deploy.prepare(scenario["args"])
|
||||
assert name in str(error.value) and "synthetic-secret" not in str(error.value)
|
||||
assert "invalid-private-value" not in str(error.value)
|
||||
assert not scenario["output"].exists()
|
||||
|
||||
|
||||
def test_diagnose_preserves_previously_generated_key_and_never_restarts(scenario,capsys):
|
||||
plan = prepared(scenario)
|
||||
before = {p.name:p.read_bytes() for p in scenario["output"].iterdir() if p.is_file()}
|
||||
scenario["base"]["services"]["connector"]["environment"]["HN_ENVIRONMENT"] = "development"
|
||||
scenario["calls"].clear()
|
||||
deploy.diagnose(scenario["output"],plan)
|
||||
assert "development" in capsys.readouterr().out
|
||||
assert before == {p.name:p.read_bytes() for p in scenario["output"].iterdir() if p.is_file()}
|
||||
assert not any("up" in c or "tag" in c or "build" in c for c in scenario["calls"])
|
||||
|
||||
|
||||
def test_diagnose_never_echoes_database_credentials(scenario,capsys):
|
||||
plan = prepared(scenario)
|
||||
env = scenario["base"]["services"]["connector"]["environment"]
|
||||
env["HN_DATABASE_URL"] = "unsupported://synthetic-db-secret@host"
|
||||
with pytest.raises(deploy.DeployError):
|
||||
deploy.diagnose(scenario["output"],plan)
|
||||
output = capsys.readouterr().out
|
||||
assert "HN_DATABASE_URL" in output and "synthetic-db-secret" not in output
|
||||
|
||||
|
||||
def test_prepare_refuses_live_subdirectory(scenario):
|
||||
scenario["args"].output = str(scenario["live"]/"broker")
|
||||
with pytest.raises(deploy.DeployError,match="outside"):
|
||||
|
||||
Reference in New Issue
Block a user