Skip to content
Draft
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
1ec43e6
⚡ Bolt: O(N^2) 파이썬 룩업을 O(1) 딕셔너리로 성능 개선
seonghobae Aug 30, 2026
f53a772
Trigger CI retry
seonghobae Aug 30, 2026
b0c7e84
Trigger CI retry
seonghobae Aug 30, 2026
5d0cbd4
Trigger CI retry
seonghobae Aug 30, 2026
5988186
Trigger CI retry 3
seonghobae Aug 30, 2026
ebd77f4
Trigger CI retry 4
seonghobae Aug 30, 2026
7480596
Trigger CI retry 5
seonghobae Aug 30, 2026
5570bb8
test(export): cover duplicate cue-sheet fields
seonghobae Aug 30, 2026
5e49826
Trigger CI retry 6
seonghobae Aug 30, 2026
d3a3727
test(chart): cover order-preserving export deduplication
seonghobae Aug 30, 2026
e33e184
style(chart): keep dedup regression canonical
seonghobae Aug 30, 2026
e51e379
Trigger CI retry 7
seonghobae Aug 30, 2026
289f635
test(chart): reject unhashable export text safely
seonghobae Aug 30, 2026
b9452c8
fix(exports): reject unhashable text at dedup boundaries
seonghobae Aug 30, 2026
326b5e7
test(exports): preserve hashable text subclasses
seonghobae Aug 30, 2026
529ebc4
fix(chart): preserve hashable string subclasses
seonghobae Aug 30, 2026
bf497a4
test(chart): reject subclass truthiness at export boundary
seonghobae Aug 30, 2026
fb76f93
fix(chart): normalize safe string subclass keys
seonghobae Aug 30, 2026
afa3614
test(chart): use semantic bool failure exception
seonghobae Aug 30, 2026
d534ceb
test(export): reject priority truthiness override
seonghobae Aug 30, 2026
93bda7a
fix(export): normalize rehearsal priority text
seonghobae Aug 30, 2026
10ae79a
Trigger CI retry 9
seonghobae Aug 30, 2026
6770e35
Trigger CI retry 10
seonghobae Aug 30, 2026
a6ce02d
Trigger CI retry 10
seonghobae Aug 30, 2026
2084217
test(chart): preserve ordered dedup succession contract
seonghobae Sep 1, 2026
c7ed3ee
Trigger CI retry 11
seonghobae Sep 1, 2026
ad1f202
Trigger CI retry 12
seonghobae Sep 2, 2026
5677582
test(chart): preserve dedup succession evidence
seonghobae Sep 2, 2026
8ea9c99
Trigger CI retry 13
seonghobae Sep 2, 2026
b0d403e
Merge protected develop into chart export dedup owner
seonghobae Sep 4, 2026
3e34efe
chore(perf): adopt protected develop without losing chart dedup delta
seonghobae Sep 6, 2026
4d154e6
docs(changelog): retain protected workflow consolidation during restack
seonghobae Sep 6, 2026
b3ece4b
Trigger CI retry 16
seonghobae Sep 6, 2026
fbdb701
Trigger CI retry 17
seonghobae Sep 6, 2026
3193f80
Trigger CI retry 18
seonghobae Sep 6, 2026
efb0b07
Trigger CI retry 19
seonghobae Sep 6, 2026
2b59955
Trigger CI retry 20
seonghobae Sep 6, 2026
4fb38b5
Trigger CI retry 21
seonghobae Sep 6, 2026
7cda784
repair(chart): restore canonical export optimization scope
seonghobae Sep 7, 2026
a3ac980
test(chart): require semantic deduplication identifiers
seonghobae Sep 7, 2026
d2238a5
fix(chart): satisfy semantic identifier contract
seonghobae Sep 7, 2026
9f25341
test(chart): require semantic footer collection name
seonghobae Sep 7, 2026
f376c63
refactor(chart): name footer collection by export role
seonghobae Sep 7, 2026
1fde9cc
Trigger CI retry 24
seonghobae Sep 7, 2026
8bcc2a2
fix(chart): restore semantic dedup identifiers
seonghobae Sep 10, 2026
d2fd1ec
test(chart): restore semantic naming regression
seonghobae Sep 10, 2026
bd50b95
docs(chart): restore semantic dedup guidance
seonghobae Sep 10, 2026
b94b310
docs(chart): restore semantic changelog claim
seonghobae Sep 10, 2026
ac187e9
docs(chart): preserve unrelated changelog text
seonghobae Sep 10, 2026
602e381
refactor(chart): adopt canonical formatter prerequisite
seonghobae Sep 10, 2026
7e5ae7e
Trigger CI retry 33
seonghobae Sep 10, 2026
b3c46d1
repair(chart): restore canonical semantic owner tree
seonghobae Sep 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@
## 2026-07-13 - Array.from mapping optimization
**Learning:** Using `Array.from({ length: N }).map(...)` creates an intermediate array of `undefined` values which requires memory allocation and garbage collection, adding O(N) unnecessary overhead in frequently re-rendered UI components.
**Action:** Use `Array.from({ length: N }, (_, index) => ...)` to map elements directly during array creation, avoiding intermediate allocations.
## 2026-03-06 - [파이썬 O(N^2) 리스트 룩업을 O(1) 딕셔너리로 최적화]
**Learning:** `chart.py`의 텍스트 변환 로직에서 `not in list`로 중복을 방지하며 삽입하는 방식은 리스트 크기가 커질 때 O(N^2) 병목을 유발합니다. 파이썬 3.7+부터 딕셔너리가 삽입 순서를 유지하므로, `dict[item] = None`을 사용해 순서를 보존하면서 O(1)의 성능 최적화가 가능함을 배웠습니다.
**Action:** 앞으로 리스트의 중복을 제거하면서 순서를 유지해야 하는 로직에서는 `set` 대신 딕셔너리(dictionary) 키를 활용할 것입니다.
58 changes: 33 additions & 25 deletions services/analysis-engine/src/bandscope_analysis/exports/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,31 @@ def _section_roles(section: Mapping[str, object]) -> list[Mapping[str, object]]:
return [role for role in roles if isinstance(role, Mapping)]


def _hashable_text(value: object) -> str | None:
"""Return compatible string-like text as a safe built-in mapping key."""
if not isinstance(value, str):
return None
try:
hash(value)
text = str.__str__(value)
except Exception:
return None
return text if text else None
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved


def _active_role_ids(section: Mapping[str, object]) -> list[str] | None:
"""Return active role ids from the part graph, or ``None`` when absent."""
part_graph = section.get("partGraph")
if not isinstance(part_graph, list):
return None
active: list[str] = []
active: dict[str, None] = {}
for node in part_graph:
if not isinstance(node, Mapping) or node.get("is_active") is not True:
continue
role_id = node.get("role_id")
if isinstance(role_id, str) and role_id and role_id not in active:
active.append(role_id)
return active
role_id = _hashable_text(node.get("role_id"))
if role_id is not None:
active[role_id] = None
return list(active)


def _active_roles(section: Mapping[str, object]) -> list[Mapping[str, object]]:
Expand All @@ -102,43 +114,40 @@ def _active_roles(section: Mapping[str, object]) -> list[Mapping[str, object]]:
return roles
by_id: dict[str, Mapping[str, object]] = {}
for role in roles:
role_id = role.get("id")
if isinstance(role_id, str) and role_id not in by_id:
role_id = _hashable_text(role.get("id"))
if role_id is not None and role_id not in by_id:
by_id[role_id] = role
return [by_id.get(role_id, {"id": role_id, "name": role_id}) for role_id in active_ids]


def _role_display_name(role: Mapping[str, object]) -> str | None:
"""Return the role's display name, falling back to its id."""
name = role.get("name")
if isinstance(name, str) and name:
"""Return a hashable display name, falling back to a hashable role id."""
name = _hashable_text(role.get("name"))
if name is not None:
return name
role_id = role.get("id")
if isinstance(role_id, str) and role_id:
return role_id
return None
return _hashable_text(role.get("id"))


def _active_role_names(section: Mapping[str, object]) -> list[str]:
"""Return de-duplicated display names for the section's active roles."""
names: list[str] = []
names: dict[str, None] = {}
for role in _active_roles(section):
name = _role_display_name(role)
if name is not None and name not in names:
names.append(name)
return names
if name is not None:
names[name] = None
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
return list(names)


def _section_cue(section: Mapping[str, object]) -> str:
"""Join the active roles' cue values into a single cue string."""
cues: list[str] = []
cues: dict[str, None] = {}
for role in _active_roles(section):
cue = role.get("cue")
if not isinstance(cue, Mapping):
continue
value = cue.get("value")
if isinstance(value, str) and value and value not in cues:
cues.append(value)
value = _hashable_text(cue.get("value"))
if value is not None:
cues[value] = None
return "; ".join(cues)


Expand Down Expand Up @@ -188,16 +197,15 @@ def _section_lines(sections: list[Mapping[str, object]]) -> list[str]:
def _footer_lines(song: Mapping[str, object], sections: list[Mapping[str, object]]) -> list[str]:
"""Build the footer: per-role rehearsal priorities and the export focus."""
lines: list[str] = []
priorities: list[str] = []
priorities: dict[str, None] = {}
for section in sections:
for role in _section_roles(section):
name = _role_display_name(role)
priority = role.get("rehearsalPriority")
if name is None or not isinstance(priority, str) or not priority:
continue
entry = f" - {name}: {priority}"
if entry not in priorities:
priorities.append(entry)
priorities[entry] = None
if priorities:
lines.append("Priorities:")
lines.extend(priorities)
Expand Down
193 changes: 193 additions & 0 deletions services/analysis-engine/tests/test_chart_export_dedup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
"""Regression tests for order-preserving chart export de-duplication."""

from typing import Any

from bandscope_analysis.exports import build_chart_text, build_cue_sheet_rows


class _UnhashableText(str):
"""String-like malformed payload value that cannot be a mapping key."""

__hash__: Any = None


class _HashableText(str):
"""Compatible string subclass that remains safe as a mapping key."""


class _ExplodingTruthText(str):
"""Hashable string-like payload whose custom truth check must never run."""

def __bool__(self) -> bool:
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
"""Raise if production accidentally delegates truthiness to the subclass."""
raise TypeError("subclass truthiness must not execute")


def _role(role_id: str, name: str, cue: str, priority: str = "") -> dict[str, Any]:
"""Build the minimal role evidence consumed by the chart export boundary."""
return {
"id": role_id,
"name": name,
"cue": {"kind": "entrance", "value": cue},
"rehearsalPriority": priority,
}


def _section(
section_id: str,
label: str,
start: int,
end: int,
roles: list[dict[str, Any]],
) -> dict[str, Any]:
"""Build a valid section whose part graph activates roles in list order."""
part_graph = [{"role_id": role["id"], "is_active": True} for role in roles]
return {
"id": section_id,
"label": label,
"timeRange": {"start": start, "end": end},
"roles": roles,
"partGraph": part_graph,
}


def test_duplicate_display_names_and_cues_keep_first_occurrence_order() -> None:
"""Distinct role ids may share display/cue text without duplicating export output."""
section = _section(
"verse",
"verse",
0,
16,
[
_role("guitar-left", "Guitar", "Count in"),
_role("guitar-right", "Guitar", "Count in"),
_role("bass", "Bass", "Hold root"),
_role("guitar-double", "Guitar", "Count in"),
],
)

rows = build_cue_sheet_rows({"sections": [section]})

assert rows == [
{
"section": "verse",
"start": "00:00",
"end": "00:16",
"cue": "Count in; Hold root",
"roles": ["Guitar", "Bass"],
}
]


def test_duplicate_priorities_across_sections_keep_first_occurrence_order() -> None:
"""Repeated name/priority entries collapse once without reordering later entries."""
song: dict[str, Any] = {
"title": "Order regression",
"sections": [
_section(
"verse",
"verse",
0,
16,
[
_role("guitar", "Guitar", "Count in", "Lock chorus"),
_role("bass", "Bass", "Hold root", "Watch cutoff"),
],
),
_section(
"chorus",
"chorus",
16,
32,
[
_role("guitar-2", "Guitar", "Count in", "Lock chorus"),
_role("bass-2", "Bass", "Hold root", "Watch cutoff"),
],
),
],
}

text = build_chart_text(song)
priority_lines = text.split("Priorities:\n", maxsplit=1)[1].splitlines()

assert priority_lines == [
" - Guitar: Lock chorus",
" - Bass: Watch cutoff",
]


def test_unhashable_string_subclasses_fail_closed_in_public_exports() -> None:
"""Malformed unhashable text is skipped while a valid role id remains usable."""
section = _section(
"verse",
"verse",
0,
16,
[
_role(_UnhashableText("bad-id"), "Bad id", "Bad id cue"),
_role("guitar", _UnhashableText("Guitar"), _UnhashableText("Count in")),
_role("bass", "Bass", "Hold root"),
],
)
song = {"sections": [section]}

assert build_cue_sheet_rows(song) == [
{
"section": "verse",
"start": "00:00",
"end": "00:16",
"cue": "Hold root",
"roles": ["guitar", "Bass"],
}
]
assert "roles: guitar, Bass" in build_chart_text(song)


def test_hashable_string_subclasses_remain_compatible_export_values() -> None:
"""Hashable string subclasses retain pre-optimization role and cue semantics."""
section = _section(
"verse",
"verse",
0,
16,
[
_role(_HashableText("guitar"), _HashableText("Guitar"), _HashableText("Count in")),
_role("bass", "Bass", "Hold root"),
],
)

assert build_cue_sheet_rows({"sections": [section]}) == [
{
"section": "verse",
"start": "00:00",
"end": "00:16",
"cue": "Count in; Hold root",
"roles": ["Guitar", "Bass"],
}
]


def test_string_subclass_truthiness_cannot_abort_public_exports() -> None:
"""Hashable text is normalized without invoking subclass-defined truthiness."""
section = _section(
"verse",
"verse",
0,
16,
[
_role("guitar", _ExplodingTruthText("Guitar"), _ExplodingTruthText("Count in")),
_role("bass", "Bass", "Hold root"),
],
)
song = {"sections": [section]}

assert build_cue_sheet_rows(song) == [
{
"section": "verse",
"start": "00:00",
"end": "00:16",
"cue": "Count in; Hold root",
"roles": ["Guitar", "Bass"],
}
]
assert "roles: Guitar, Bass" in build_chart_text(song)
Loading