askrobots / dbbasic-object-server
Public
Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
danq9
signup: the person chooses the password and name on the confirm page
83c7aa6
2 weeks, 5 days ago
History
test_object_feature_flags.py · 3.0 KB · 64 lines
| 1 | """The shared opt-in and kill-switch gates (object_feature_flags). |
| 2 | |
| 3 | These were six copies before; the tests pin the posture every copy had, |
| 4 | so the extraction cannot quietly change what an operator's flag means. |
| 5 | """ |
| 6 | |
| 7 | import object_email |
| 8 | import object_feature_flags |
| 9 | import object_records |
| 10 | |
| 11 | |
| 12 | def _flags(tmp_path, rows): |
| 13 | data_dir = tmp_path / "data" |
| 14 | schema_dir = data_dir / "schemas" |
| 15 | schema_dir.mkdir(parents=True) |
| 16 | (schema_dir / "feature_flags.json").write_text( |
| 17 | '{"name": "feature_flags", "fields": [{"name": "id"}, {"name": "flag"}, {"name": "value"}]}') |
| 18 | for index, (flag, value) in enumerate(rows): |
| 19 | object_records.create_collection_record( |
| 20 | "feature_flags", {"id": f"f{index}", "flag": flag, "value": value}, |
| 21 | base_dir=data_dir, actor="test") |
| 22 | return data_dir |
| 23 | |
| 24 | |
| 25 | def test_env_opt_in_is_off_unless_the_operator_wrote_it(): |
| 26 | """Adoption gate: a fresh box talks to nobody.""" |
| 27 | assert object_feature_flags.env_opt_in("X", {}) is False |
| 28 | assert object_feature_flags.env_opt_in("X", {"X": ""}) is False |
| 29 | assert object_feature_flags.env_opt_in("X", {"X": "false"}) is False |
| 30 | assert object_feature_flags.env_opt_in("X", {"X": " TRUE "}) is True |
| 31 | assert object_feature_flags.env_opt_in("X", {"X": "1"}) is True |
| 32 | |
| 33 | |
| 34 | def test_kill_switch_is_on_without_a_table_a_row_or_a_value(tmp_path): |
| 35 | """Brownout lever: only an explicit off turns a pass off. A switch that |
| 36 | failed closed on a missing table would turn every fresh box's passes |
| 37 | off for a reason nobody chose.""" |
| 38 | missing = tmp_path / "nothing" |
| 39 | assert object_feature_flags.kill_switch_on("mail_sync_enabled", base_dir=missing) is True |
| 40 | data_dir = _flags(tmp_path, [("other_enabled", "off"), ("mail_sync_enabled", "")]) |
| 41 | assert object_feature_flags.kill_switch_on("mail_sync_enabled", base_dir=data_dir) is True |
| 42 | assert object_feature_flags.kill_switch_on("other_enabled", base_dir=data_dir) is False |
| 43 | |
| 44 | |
| 45 | def test_the_existing_switches_now_read_through_the_shared_gate(tmp_path): |
| 46 | """email_pass_enabled keeps its name and its meaning.""" |
| 47 | data_dir = _flags(tmp_path, [("email_enabled", "no")]) |
| 48 | assert object_email.email_pass_enabled(base_dir=data_dir) is False |
| 49 | |
| 50 | |
| 51 | def test_refusal_names_what_to_set(tmp_path): |
| 52 | """A refusal that does not name the variable is a refusal nobody can act on.""" |
| 53 | data_dir = _flags(tmp_path, [("mail_sync_enabled", "off")]) |
| 54 | off_env = object_feature_flags.refusal( |
| 55 | env_name="DBBASIC_ENABLE_MAIL_SYNC", flag="mail_sync_enabled", |
| 56 | base_dir=data_dir, env={}) |
| 57 | assert "DBBASIC_ENABLE_MAIL_SYNC" in off_env |
| 58 | off_flag = object_feature_flags.refusal( |
| 59 | env_name="DBBASIC_ENABLE_MAIL_SYNC", flag="mail_sync_enabled", |
| 60 | base_dir=data_dir, env={"DBBASIC_ENABLE_MAIL_SYNC": "true"}) |
| 61 | assert "mail_sync_enabled" in off_flag |
| 62 | assert object_feature_flags.refusal( |
| 63 | env_name="DBBASIC_ENABLE_MAIL_SYNC", flag="mail_sync_enabled", |
| 64 | base_dir=tmp_path / "nothing", env={"DBBASIC_ENABLE_MAIL_SYNC": "yes"}) is None |