2026-07-10 17:36:08 +00:00
|
|
|
require_relative "test_helper"
|
|
|
|
|
|
|
|
|
|
class ConfigTest < Minitest::Test
|
|
|
|
|
def test_nil_contents_is_unconfigured
|
|
|
|
|
config = Backlog::Config.new(nil)
|
|
|
|
|
refute config.configured?
|
|
|
|
|
assert_nil config.board
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_blank_contents_is_unconfigured
|
|
|
|
|
config = Backlog::Config.new(" \n")
|
|
|
|
|
refute config.configured?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_reads_board_key
|
2026-07-12 20:04:12 +00:00
|
|
|
config = Backlog::Config.new("board=llf-schema\n")
|
2026-07-10 17:36:08 +00:00
|
|
|
assert config.configured?
|
|
|
|
|
assert_equal "llf-schema", config.board
|
|
|
|
|
end
|
|
|
|
|
|
2026-07-12 20:04:12 +00:00
|
|
|
def test_reads_legacy_yaml_style_board_key
|
|
|
|
|
config = Backlog::Config.new("---\nboard: llf-schema\n")
|
|
|
|
|
assert config.configured?
|
|
|
|
|
assert_equal "llf-schema", config.board
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_lines_without_separator_are_ignored
|
|
|
|
|
config = Backlog::Config.new("# comment\njunk line\n")
|
2026-07-10 17:36:08 +00:00
|
|
|
refute config.configured?
|
|
|
|
|
end
|
|
|
|
|
|
2026-07-12 20:04:12 +00:00
|
|
|
def test_contents_without_board_key_is_unconfigured
|
|
|
|
|
config = Backlog::Config.new("other=value\n")
|
2026-07-10 17:36:08 +00:00
|
|
|
refute config.configured?
|
|
|
|
|
end
|
2026-07-12 19:54:08 +00:00
|
|
|
|
|
|
|
|
def test_reads_tracker_key
|
2026-07-12 20:04:12 +00:00
|
|
|
config = Backlog::Config.new("tracker=forgejo:jared/cc-os\n")
|
2026-07-12 19:54:08 +00:00
|
|
|
assert config.tracker_configured?
|
|
|
|
|
assert_equal "forgejo:jared/cc-os", config.tracker
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_tracker_unconfigured_when_absent
|
2026-07-12 20:04:12 +00:00
|
|
|
config = Backlog::Config.new("board=llf-schema\n")
|
2026-07-12 19:54:08 +00:00
|
|
|
refute config.tracker_configured?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_merge_sets_new_key_on_nil_contents
|
2026-07-12 20:04:12 +00:00
|
|
|
contents = Backlog::Config.merge(nil, "tracker", "forgejo:jared/cc-os")
|
|
|
|
|
assert_equal "tracker=forgejo:jared/cc-os\n", contents
|
2026-07-12 19:54:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_merge_preserves_other_keys
|
2026-07-12 20:04:12 +00:00
|
|
|
existing = "board=llf-schema\nother=kept\n"
|
2026-07-12 19:54:08 +00:00
|
|
|
updated_contents = Backlog::Config.merge(existing, "tracker", "planka:llf-schema")
|
|
|
|
|
updated = Backlog::Config.new(updated_contents)
|
|
|
|
|
|
|
|
|
|
assert_equal "llf-schema", updated.board
|
|
|
|
|
assert_equal "planka:llf-schema", updated.tracker
|
|
|
|
|
assert_equal "kept", updated.to_h["other"]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_merge_overwrites_existing_value_for_key
|
2026-07-12 20:04:12 +00:00
|
|
|
existing = "tracker=repo:old\n"
|
2026-07-12 19:54:08 +00:00
|
|
|
updated = Backlog::Config.new(Backlog::Config.merge(existing, "tracker", "repo:new"))
|
|
|
|
|
assert_equal "repo:new", updated.tracker
|
|
|
|
|
end
|
2026-07-12 21:47:01 +00:00
|
|
|
|
|
|
|
|
def test_reads_spaced_key_value_lines
|
|
|
|
|
config = Backlog::Config.new("version = 1\nhub = my-hub\n")
|
|
|
|
|
assert_equal "1", config.to_h["version"]
|
|
|
|
|
assert_equal "my-hub", config.to_h["hub"]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_merge_output_has_no_spaces_around_equals
|
|
|
|
|
contents = Backlog::Config.merge(nil, "tracker", "forgejo:jared/cc-os")
|
|
|
|
|
assert_equal "tracker=forgejo:jared/cc-os\n", contents
|
|
|
|
|
refute_includes contents, " = "
|
|
|
|
|
refute_includes contents, "= "
|
|
|
|
|
refute_includes contents, " ="
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_merge_normalizes_existing_spaced_lines_on_rewrite
|
|
|
|
|
existing = "version = 1\nhub = my-hub\n"
|
|
|
|
|
updated_contents = Backlog::Config.merge(existing, "tracker", "planka:board")
|
|
|
|
|
updated_contents.each_line do |line|
|
|
|
|
|
next if line.strip.empty?
|
|
|
|
|
|
|
|
|
|
refute_match(/\s=\s|\s=|=\s/, line, "expected normalized key=value, got #{line.inspect}")
|
|
|
|
|
end
|
|
|
|
|
updated = Backlog::Config.new(updated_contents)
|
|
|
|
|
assert_equal "1", updated.to_h["version"]
|
|
|
|
|
assert_equal "my-hub", updated.to_h["hub"]
|
|
|
|
|
assert_equal "planka:board", updated.tracker
|
|
|
|
|
end
|
2026-07-13 13:18:45 +00:00
|
|
|
|
|
|
|
|
def test_board_id_reader
|
|
|
|
|
config = Backlog::Config.new("tracker=planka:board\nboard_id=42\n")
|
|
|
|
|
assert_equal "42", config.board_id
|
|
|
|
|
assert_nil Backlog::Config.new(nil).board_id
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_set_preserves_comments_and_blank_lines
|
|
|
|
|
existing = "# managed by cc-os\ntracker=planka:board\n\n# stamped by os-status\nversion=3\n"
|
|
|
|
|
updated = Backlog::Config.set(existing, "board_id", "42")
|
|
|
|
|
assert_equal "# managed by cc-os\ntracker=planka:board\n\n# stamped by os-status\nversion=3\nboard_id=42\n",
|
|
|
|
|
updated
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_set_replaces_existing_key_in_place
|
|
|
|
|
existing = "# top comment\nboard_id=old\ntracker=planka:board\n"
|
|
|
|
|
updated = Backlog::Config.set(existing, "board_id", "new")
|
|
|
|
|
assert_equal "# top comment\nboard_id=new\ntracker=planka:board\n", updated
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_set_normalizes_spaced_key_value_lines_only
|
|
|
|
|
existing = "# note\nversion = 1\n"
|
|
|
|
|
updated = Backlog::Config.set(existing, "board_id", "42")
|
|
|
|
|
assert_equal "# note\nversion=1\nboard_id=42\n", updated
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_set_on_nil_contents
|
|
|
|
|
assert_equal "board_id=42\n", Backlog::Config.set(nil, "board_id", "42")
|
|
|
|
|
end
|
2026-07-13 16:27:43 +00:00
|
|
|
|
|
|
|
|
def test_planka_board_prefers_explicit_board_key
|
|
|
|
|
config = Backlog::Config.new("board=explicit\ntracker=planka:from-tracker\n")
|
|
|
|
|
assert_equal "explicit", config.planka_board
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_planka_board_derives_from_planka_tracker
|
|
|
|
|
config = Backlog::Config.new("tracker=planka:my-board\n")
|
|
|
|
|
assert_equal "my-board", config.planka_board
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_planka_board_nil_for_non_planka_tracker
|
|
|
|
|
assert_nil Backlog::Config.new("tracker=forgejo:me/repo\n").planka_board
|
|
|
|
|
assert_nil Backlog::Config.new(nil).planka_board
|
|
|
|
|
end
|
2026-07-10 17:36:08 +00:00
|
|
|
end
|