From 93b425459eae41ee70a0ca887a71380e5e2e898d Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Mon, 31 Aug 2026 07:33:21 +0000 Subject: [PATCH 01/13] feat(workspace): name tonight's first leftover last-dropout remaining return on the map Name who comes back after leftover last-dropout remaining: leftover sit-out, leftover return with remaining leftover, leftover last-return, leftover last-dropout as a cohort of at least two named parts, leftover last-dropout remaining, then leftover last-dropout remaining return when at least one leftover last-dropout remaining named part is own-property active. --- AGENTS.md | 2 +- ARCHITECTURE.md | 2 +- CHANGELOG.md | 1 + CLAUDE.md | 2 +- .../src/features/workspace/Workspace.test.tsx | 196 +++++++ .../src/features/workspace/Workspace.tsx | 28 + ...opoutRemainingReturn.selected-role.test.ts | 133 +++++ ...LeftoverLastDropoutRemainingReturn.test.ts | 484 ++++++++++++++++ ...firstLeftoverLastDropoutRemainingReturn.ts | 540 ++++++++++++++++++ apps/desktop/src/locales/en/common.json | 4 + apps/desktop/src/locales/ko/common.json | 4 + docs/design-system/component-contract.md | 1 + ...-leftover-last-dropout-remaining-return.md | 18 + 13 files changed, 1412 insertions(+), 3 deletions(-) create mode 100644 apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.selected-role.test.ts create mode 100644 apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.test.ts create mode 100644 apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.ts create mode 100644 docs/doctoring/first-leftover-last-dropout-remaining-return.md diff --git a/AGENTS.md b/AGENTS.md index b9a67ce17..a2ff21140 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,7 +1,7 @@ # AGENTS.md ## Project overview -- BandScope is a local-first desktop app for rehearsal prep: a practical song view with likely harmony by section and by instrument or vocal role, form and groove cues, stems, playable ranges, simplification guidance, transposition or setup cues, part-overlap cues, visible confidence, and rehearsal priorities. +- BandScope is a local-first desktop app for rehearsal prep: a practical song view with likely harmony by section and by instrument or vocal role, form and groove cues, stems, playable ranges, leftover last-dropout remaining return cues after leftover last-dropout remaining, simplification guidance, transposition or setup cues, part-overlap cues, visible confidence, and rehearsal priorities. - Authoritative delivery rules live in `ARCHITECTURE.md`, `docs/plans/`, and the root verification scripts. - Brand, tone, UX copy, and prioritization rules live in `docs/brand-story.md` and must be applied to PRDs, TRDs, UI copy, onboarding, empty states, and error messages. - App security rules live in `docs/security/app-security.md` and must be applied to file handling, URL intake, subprocesses, IPC, WebView usage, model loading, updates, logging, cache handling, and export behavior. diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index ca0df5ac4..4130114a6 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -82,7 +82,7 @@ Last updated: 2026-03-11 - likely harmony by section and by role - section roadmap with entries, dropouts, pickups, stops, tags, and handoffs - groove and timing cues relevant to locking the band together - - playable ranges and density or overlap warnings, with the ready workspace naming tonight's first span and the next instrument check + - playable ranges and density or overlap warnings, with the ready workspace naming tonight's first span and tonight's first leftover last-dropout remaining return after leftover last-dropout remaining - simplification, transposition, capo, tuning, or setup cues where applicable - role-specific rehearsal priorities and confidence flags - cue-sheet or chart-style exports that summarize the analysis in rehearsal-friendly form diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b6f7e784..a3f972c36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Added +- Name tonight's first leftover last-dropout remaining return on the ready rehearsal map and tell the player who comes back after leftover last-dropout remaining. - Name tonight's first playable range on the ready rehearsal map and tell the player to check that span on their instrument before the section. - Display the analyzed song tempo (BPM) as a badge in the rehearsal workspace. - 각 합주 역할(Role)별 개인 연습 진행도를 0~100% 범위로 기록 및 시각화할 수 있는 연습 진척도(`practiceProgress`) 트래커 기능 추가. UI 컨트롤(슬라이더 및 +/- 버튼)과 한/영 다국어 지원 포함. diff --git a/CLAUDE.md b/CLAUDE.md index b5a34c1fa..116388d16 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -51,7 +51,7 @@ BandScope is a local-first desktop app for rehearsal prep: it turns a song into Three layers, decoupled through shared contracts: -- `apps/desktop` — Tauri 2 + Vite + React 19 shell (Tailwind 4, Base UI, Storybook). Feature screens live in `src/features/` (home, workspace, chords, ranges, player, settings). The ready workspace names tonight's first playable range and the next instrument check. `src/lib/analysis.ts` and `src/lib/job_runner.ts` call typed Tauri IPC commands, with a browser fallback that serves demo data when not running inside Tauri. +- `apps/desktop` — Tauri 2 + Vite + React 19 shell (Tailwind 4, Base UI, Storybook). Feature screens live in `src/features/` (home, workspace, chords, ranges, player, settings). The ready workspace names tonight's first playable range and tonight's first leftover last-dropout remaining return after leftover last-dropout remaining. `src/lib/analysis.ts` and `src/lib/job_runner.ts` call typed Tauri IPC commands, with a browser fallback that serves demo data when not running inside Tauri. - `apps/desktop/src-tauri/src/main.rs` — the Rust orchestration boundary. Tauri commands (`start_analysis_job`, `get_analysis_job_status`, `select_local_audio_source`, `import_youtube_url`) validate untrusted input (project IDs, file paths, URLs) and spawn the Python engine as a subprocess. There is no loopback HTTP listener and no network path for local analysis. - `services/analysis-engine` — Python package `bandscope_analysis` (librosa/numpy). Entry point `cli.py` reads a JSON job request on stdin and prints a structured job-status JSON envelope on stdout (`--progress-jsonl` streams progress lines). `api.py` orchestrates the pipeline across the `separation`, `sections`, `roles`, `chords`, `ranges`, `temporal`, `transcription`, and `youtube` modules. diff --git a/apps/desktop/src/features/workspace/Workspace.test.tsx b/apps/desktop/src/features/workspace/Workspace.test.tsx index 7837bf80e..4877dff1b 100644 --- a/apps/desktop/src/features/workspace/Workspace.test.tsx +++ b/apps/desktop/src/features/workspace/Workspace.test.tsx @@ -140,6 +140,202 @@ describe("Workspace", () => { expect(screen.getByText(/Verse harmony pass/i)).toBeTruthy(); }); + it("names tonight's first leftover last-dropout remaining return after leftover last-dropout remaining", () => { + setNavigatorLanguage("en-US"); + const song = createDemoRehearsalSong(); + const verse = song.sections[0]!; + song.sections = [ + { + ...verse, + partGraph: verse.partGraph.map((node) => + node.role_id === "bass-guitar" || + node.role_id === "keys-right" || + node.role_id === "lead-vocal" + ? { ...node, is_active: false } + : node + ) + }, + { + ...verse, + id: "chorus-1", + label: "chorus", + timeRange: { start: verse.timeRange.end, end: verse.timeRange.end + 20 }, + partGraph: verse.partGraph.map((node) => + node.role_id === "keys-right" || node.role_id === "lead-vocal" + ? { ...node, is_active: false } + : node + ) + }, + { + ...verse, + id: "bridge-1", + label: "bridge", + timeRange: { + start: verse.timeRange.end + 20, + end: verse.timeRange.end + 40 + }, + partGraph: verse.partGraph.map((node) => + node.role_id === "lead-vocal" ? { ...node, is_active: false } : node + ) + }, + { + ...verse, + id: "outro-1", + label: "outro", + timeRange: { + start: verse.timeRange.end + 40, + end: verse.timeRange.end + 60 + } + }, + { + ...verse, + id: "tag-1", + label: "tag", + timeRange: { + start: verse.timeRange.end + 60, + end: verse.timeRange.end + 80 + }, + partGraph: verse.partGraph.map((node) => + node.role_id === "keys-right" || node.role_id === "bass-guitar" + ? { ...node, is_active: false } + : node + ) + }, + { + ...verse, + id: "coda-1", + label: "stop", + timeRange: { + start: verse.timeRange.end + 80, + end: verse.timeRange.end + 100 + }, + partGraph: verse.partGraph.map((node) => + node.role_id === "bass-guitar" ? { ...node, is_active: false } : node + ) + }, + { + ...verse, + id: "ending-1", + label: "ending", + timeRange: { + start: verse.timeRange.end + 100, + end: verse.timeRange.end + 120 + } + } + ]; + + render(); + + const callout = screen.getByTestId("first-leftover-last-dropout-remaining-return"); + expect(callout).toHaveTextContent("Tonight's first leftover last-dropout remaining return"); + expect(callout).toHaveTextContent( + "Bass Guitar comes back at ending after staying out through leftover last-dropout remaining at stop. Count Bass Guitar in from the top of ending." + ); + }); + + it("tells the leftover last-dropout remaining return to come back after leftover last-dropout remaining", () => { + setNavigatorLanguage("en-US"); + const song = createDemoRehearsalSong(); + const verse = song.sections[0]!; + song.sections = [ + { + ...verse, + partGraph: verse.partGraph.map((node) => + node.role_id === "bass-guitar" || + node.role_id === "keys-right" || + node.role_id === "lead-vocal" + ? { ...node, is_active: false } + : node + ) + }, + { + ...verse, + id: "chorus-1", + label: "chorus", + timeRange: { start: verse.timeRange.end, end: verse.timeRange.end + 20 }, + partGraph: verse.partGraph.map((node) => + node.role_id === "keys-right" || node.role_id === "lead-vocal" + ? { ...node, is_active: false } + : node + ) + }, + { + ...verse, + id: "bridge-1", + label: "bridge", + timeRange: { + start: verse.timeRange.end + 20, + end: verse.timeRange.end + 40 + }, + partGraph: verse.partGraph.map((node) => + node.role_id === "lead-vocal" ? { ...node, is_active: false } : node + ) + }, + { + ...verse, + id: "outro-1", + label: "outro", + timeRange: { + start: verse.timeRange.end + 40, + end: verse.timeRange.end + 60 + } + }, + { + ...verse, + id: "tag-1", + label: "tag", + timeRange: { + start: verse.timeRange.end + 60, + end: verse.timeRange.end + 80 + }, + partGraph: verse.partGraph.map((node) => + node.role_id === "keys-right" || node.role_id === "bass-guitar" + ? { ...node, is_active: false } + : node + ) + }, + { + ...verse, + id: "coda-1", + label: "stop", + timeRange: { + start: verse.timeRange.end + 80, + end: verse.timeRange.end + 100 + }, + partGraph: verse.partGraph.map((node) => + node.role_id === "bass-guitar" ? { ...node, is_active: false } : node + ) + }, + { + ...verse, + id: "ending-1", + label: "ending", + timeRange: { + start: verse.timeRange.end + 100, + end: verse.timeRange.end + 120 + } + } + ]; + + render(); + fireEvent.click(screen.getByRole("tab", { name: "Bass Guitar" })); + + expect(screen.getByTestId("first-leftover-last-dropout-remaining-return")).toHaveTextContent( + "Bass Guitar comes back at ending after staying out through leftover last-dropout remaining at stop. Come back from leftover last-dropout remaining at the top of ending." + ); + }); + + it("asks the player to confirm leftover last-dropout remaining return when every part stays active", () => { + setNavigatorLanguage("en-US"); + const song = createDemoRehearsalSong(); + + render(); + + expect(screen.getByTestId("first-leftover-last-dropout-remaining-return")).toHaveTextContent( + "Tonight's first leftover last-dropout remaining return still needs a named leftover last-dropout remaining and a later remaining return. Confirm who comes back after leftover last-dropout remaining before the first section." + ); + }); + it("names tonight's first playable range and the next instrument check", () => { setNavigatorLanguage("en-US"); const song = createDemoRehearsalSong(); diff --git a/apps/desktop/src/features/workspace/Workspace.tsx b/apps/desktop/src/features/workspace/Workspace.tsx index d44e20777..dae1b6b88 100644 --- a/apps/desktop/src/features/workspace/Workspace.tsx +++ b/apps/desktop/src/features/workspace/Workspace.tsx @@ -5,6 +5,7 @@ import { SectionRoadmap } from "./SectionRoadmap"; import { GrooveMap } from "./GrooveMap"; import { PracticeProgress } from "./PracticeProgress"; import { fillRangeCopy, firstRangeSqueeze } from "./firstRangeSqueeze"; +import { firstLeftoverLastDropoutRemainingReturn } from "./firstLeftoverLastDropoutRemainingReturn"; import { createTranslator, detectPreferredLocale } from "../../i18n"; import { generateCueSheetCsv, generateChartSummaryJson, generateMetadataHandoffJson, sanitizeFilename } from "../../lib/export"; import { Button } from "@/components/ui/button"; @@ -163,6 +164,25 @@ export function Workspace({ song, sourceBootstrap = null, onSongUpdate }: Worksp } ) : t("workspaceFirstRangeMissing"); + const namedLeftoverLastDropoutRemainingReturn = useMemo( + () => firstLeftoverLastDropoutRemainingReturn(song, activeRole), + [activeRole, song] + ); + const firstLeftoverLastDropoutRemainingReturnCopy = namedLeftoverLastDropoutRemainingReturn + ? fillRangeCopy( + t( + activeRole && activeRole === namedLeftoverLastDropoutRemainingReturn.returningRoleId + ? "workspaceFirstLeftoverLastDropoutRemainingReturnComeIn" + : "workspaceFirstLeftoverLastDropoutRemainingReturnNamed" + ), + { + returningRoleName: namedLeftoverLastDropoutRemainingReturn.returningRoleName, + remainingRoleName: namedLeftoverLastDropoutRemainingReturn.remainingRoleName, + sectionLabel: namedLeftoverLastDropoutRemainingReturn.sectionLabel, + remainingSectionLabel: namedLeftoverLastDropoutRemainingReturn.remainingSectionLabel + } + ) + : t("workspaceFirstLeftoverLastDropoutRemainingReturnMissing"); /** Handle the practice progress change internally by immutably updating the song state. */ const handlePracticeProgressChange = (newProgress: number) => { @@ -309,6 +329,14 @@ export function Workspace({ song, sourceBootstrap = null, onSongUpdate }: Worksp

{t("workspaceFirstRangeTitle")}

{firstRangeCopy}

+
+

{t("workspaceFirstLeftoverLastDropoutRemainingReturnTitle")}

+

{firstLeftoverLastDropoutRemainingReturnCopy}

+
diff --git a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.selected-role.test.ts b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.selected-role.test.ts new file mode 100644 index 000000000..ce81eaffe --- /dev/null +++ b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.selected-role.test.ts @@ -0,0 +1,133 @@ +import { createDemoRehearsalSong, type RehearsalSong } from "@bandscope/shared-types"; +import { describe, expect, it } from "vitest"; +import { firstLeftoverLastDropoutRemainingReturn } from "./firstLeftoverLastDropoutRemainingReturn"; + +function sectionWithInactiveRoles( + template: RehearsalSong["sections"][number], + id: string, + label: RehearsalSong["sections"][number]["label"], + start: number, + inactiveRoleIds: readonly string[] +): RehearsalSong["sections"][number] { + const inactive = new Set(inactiveRoleIds); + return { + ...template, + id, + label, + timeRange: { start, end: start + 20 }, + partGraph: template.partGraph.map((node) => ({ + ...node, + is_active: !inactive.has(node.role_id) + })) + }; +} + +describe("firstLeftoverLastDropoutRemainingReturn selected-role search", () => { + it("keeps searching after the selected part newly drops out during leftover last-return tutti", () => { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + const song: RehearsalSong = { + ...seed, + sections: [ + sectionWithInactiveRoles(template, "verse-1", "verse", 0, [ + "bass-guitar", + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "chorus-1", "chorus", 20, [ + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "bridge-1", "bridge", 40, ["lead-vocal"]), + sectionWithInactiveRoles(template, "outro-1", "outro", 60, []), + sectionWithInactiveRoles(template, "tag-1", "tag", 80, []), + sectionWithInactiveRoles(template, "coda-1", "stop", 100, ["bass-guitar", "keys-right"]), + sectionWithInactiveRoles(template, "ending-1", "ending", 120, ["bass-guitar"]), + sectionWithInactiveRoles(template, "final-1", "final", 140, []) + ] + }; + + expect(firstLeftoverLastDropoutRemainingReturn(song, "bass-guitar")).toEqual({ + sectionLabel: "final", + remainingSectionLabel: "ending", + dropoutSectionLabel: "stop", + lastReturnSectionLabel: "outro", + leftoverSectionLabel: "chorus", + fromSectionLabel: "verse", + remainingRoleId: "bass-guitar", + remainingRoleName: "Bass Guitar", + returningRoleId: "bass-guitar", + returningRoleName: "Bass Guitar" + }); + }); + + it("does not tell leftover last-dropout remaining without a later remaining return to come in", () => { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + const song: RehearsalSong = { + ...seed, + sections: [ + sectionWithInactiveRoles(template, "verse-1", "verse", 0, [ + "bass-guitar", + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "chorus-1", "chorus", 20, [ + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "bridge-1", "bridge", 40, ["lead-vocal"]), + sectionWithInactiveRoles(template, "outro-1", "outro", 60, []), + sectionWithInactiveRoles(template, "tag-1", "tag", 80, ["keys-right", "bass-guitar"]), + sectionWithInactiveRoles(template, "coda-1", "stop", 100, ["bass-guitar"]) + ] + }; + + expect(firstLeftoverLastDropoutRemainingReturn(song, "bass-guitar")).toBeNull(); + }); + + it("does not show another part's leftover last-dropout remaining return to a selected part that stayed active", () => { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + const selectedRole = { + ...template.roles[0]!, + id: "always-active", + name: "Always Active" + }; + const selectedTemplate: RehearsalSong["sections"][number] = { + ...template, + roles: [...template.roles, selectedRole], + partGraph: [ + ...template.partGraph, + { + ...template.partGraph[0]!, + role_id: "always-active", + is_active: true, + handoff_to: [], + handoff_from: [] + } + ] + }; + const song: RehearsalSong = { + ...seed, + sections: [ + sectionWithInactiveRoles(selectedTemplate, "verse-1", "verse", 0, [ + "bass-guitar", + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(selectedTemplate, "chorus-1", "chorus", 20, [ + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(selectedTemplate, "bridge-1", "bridge", 40, ["lead-vocal"]), + sectionWithInactiveRoles(selectedTemplate, "outro-1", "outro", 60, []), + sectionWithInactiveRoles(selectedTemplate, "tag-1", "tag", 80, ["keys-right", "bass-guitar"]), + sectionWithInactiveRoles(selectedTemplate, "coda-1", "stop", 100, ["bass-guitar"]), + sectionWithInactiveRoles(selectedTemplate, "ending-1", "ending", 120, []) + ] + }; + + expect(firstLeftoverLastDropoutRemainingReturn(song, "always-active")).toBeNull(); + }); +}); diff --git a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.test.ts b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.test.ts new file mode 100644 index 000000000..a6c9468d6 --- /dev/null +++ b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.test.ts @@ -0,0 +1,484 @@ +import { createDemoRehearsalSong, type RehearsalSong } from "@bandscope/shared-types"; +import { describe, expect, it } from "vitest"; +import { fillRangeCopy } from "./firstRangeSqueeze"; +import { firstLeftoverLastDropoutRemainingReturn } from "./firstLeftoverLastDropoutRemainingReturn"; + +function sectionWithInactiveRoles( + template: RehearsalSong["sections"][number], + id: string, + label: string, + start: number, + inactiveRoleIds: readonly string[], + activeOnlyRoles = false +): RehearsalSong["sections"][number] { + const inactive = new Set(inactiveRoleIds); + const partGraph = template.partGraph.map((node) => ({ + ...node, + is_active: !inactive.has(node.role_id) + })); + return { + ...template, + id, + label: label as RehearsalSong["sections"][number]["label"], + timeRange: { start, end: start + 20 }, + partGraph, + roles: activeOnlyRoles + ? template.roles.filter((role) => !inactive.has(role.id)) + : template.roles + }; +} + +function leftoverThenLastReturnThenDropoutThenRemainingThenReturn( + remainingRoleId = "bass-guitar", + returningDropoutId = "keys-right", + lastRoleId = "lead-vocal" +): RehearsalSong { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + return { + ...seed, + sections: [ + sectionWithInactiveRoles(template, "verse-1", "verse", 0, [ + remainingRoleId, + returningDropoutId, + lastRoleId + ]), + sectionWithInactiveRoles(template, "chorus-1", "chorus", 20, [ + returningDropoutId, + lastRoleId + ]), + sectionWithInactiveRoles(template, "bridge-1", "bridge", 40, [lastRoleId]), + sectionWithInactiveRoles(template, "outro-1", "outro", 60, []), + sectionWithInactiveRoles(template, "tag-1", "tag", 80, [ + remainingRoleId, + returningDropoutId + ]), + sectionWithInactiveRoles(template, "coda-1", "stop", 100, [remainingRoleId]), + sectionWithInactiveRoles(template, "ending-1", "ending", 120, []) + ] + }; +} + +const namedBassReturn = { + sectionLabel: "ending", + remainingSectionLabel: "stop", + dropoutSectionLabel: "tag", + lastReturnSectionLabel: "outro", + leftoverSectionLabel: "chorus", + fromSectionLabel: "verse", + remainingRoleId: "bass-guitar", + remainingRoleName: "Bass Guitar", + returningRoleId: "bass-guitar", + returningRoleName: "Bass Guitar" +} as const; + +describe("firstLeftoverLastDropoutRemainingReturn", () => { + it("returns null on the demo song where every graph node is active", () => { + expect(firstLeftoverLastDropoutRemainingReturn(createDemoRehearsalSong())).toBeNull(); + }); + + it("names the leftover last-dropout remaining return after leftover last-dropout remaining", () => { + expect(firstLeftoverLastDropoutRemainingReturn(leftoverThenLastReturnThenDropoutThenRemainingThenReturn())).toEqual( + namedBassReturn + ); + }); + + it("uses song-wide role names when inactive analysis roles are omitted from section roles", () => { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + const song: RehearsalSong = { + ...seed, + sections: [ + sectionWithInactiveRoles(template, "opening-1", "opening", 0, []), + sectionWithInactiveRoles( + template, + "bridge-1", + "bridge", + 20, + ["bass-guitar", "keys-right", "lead-vocal"], + true + ), + sectionWithInactiveRoles( + template, + "chorus-1", + "chorus", + 40, + ["keys-right", "lead-vocal"], + true + ), + sectionWithInactiveRoles(template, "tag-1", "tag", 60, ["lead-vocal"], true), + sectionWithInactiveRoles(template, "outro-1", "outro", 80, [], true), + sectionWithInactiveRoles(template, "coda-1", "stop", 100, ["keys-right", "bass-guitar"], true), + sectionWithInactiveRoles(template, "ending-1", "ending", 120, ["bass-guitar"], true), + sectionWithInactiveRoles(template, "final-1", "final", 140, [], true) + ] + }; + + expect(firstLeftoverLastDropoutRemainingReturn(song)).toEqual({ + sectionLabel: "final", + remainingSectionLabel: "ending", + dropoutSectionLabel: "stop", + lastReturnSectionLabel: "outro", + leftoverSectionLabel: "chorus", + fromSectionLabel: "bridge", + remainingRoleId: "bass-guitar", + remainingRoleName: "Bass Guitar", + returningRoleId: "bass-guitar", + returningRoleName: "Bass Guitar" + }); + }); + + it("treats repeated form labels as distinct timeline sections", () => { + const song = leftoverThenLastReturnThenDropoutThenRemainingThenReturn(); + song.sections[6] = { + ...song.sections[6]!, + label: song.sections[5]!.label + }; + + expect(firstLeftoverLastDropoutRemainingReturn(song)).toEqual({ + ...namedBassReturn, + sectionLabel: "stop" + }); + }); + + it("skips continued leftover last-dropout remaining until leftover last-dropout remaining return", () => { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + const song: RehearsalSong = { + ...seed, + sections: [ + sectionWithInactiveRoles(template, "verse-1", "verse", 0, [ + "bass-guitar", + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "chorus-1", "chorus", 20, [ + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "bridge-1", "bridge", 40, ["lead-vocal"]), + sectionWithInactiveRoles(template, "outro-1", "outro", 60, []), + sectionWithInactiveRoles(template, "tag-1", "tag", 80, ["keys-right", "bass-guitar"]), + sectionWithInactiveRoles(template, "coda-1", "stop", 100, ["bass-guitar"]), + sectionWithInactiveRoles(template, "ending-1", "ending", 120, ["bass-guitar"]), + sectionWithInactiveRoles(template, "final-1", "final", 140, []) + ] + }; + + expect(firstLeftoverLastDropoutRemainingReturn(song)).toEqual({ + sectionLabel: "final", + remainingSectionLabel: "stop", + dropoutSectionLabel: "tag", + lastReturnSectionLabel: "outro", + leftoverSectionLabel: "chorus", + fromSectionLabel: "verse", + remainingRoleId: "bass-guitar", + remainingRoleName: "Bass Guitar", + returningRoleId: "bass-guitar", + returningRoleName: "Bass Guitar" + }); + }); + + it("fails closed when leftover last-dropout remaining never returns", () => { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + const song: RehearsalSong = { + ...seed, + sections: [ + sectionWithInactiveRoles(template, "verse-1", "verse", 0, [ + "bass-guitar", + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "chorus-1", "chorus", 20, [ + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "bridge-1", "bridge", 40, ["lead-vocal"]), + sectionWithInactiveRoles(template, "outro-1", "outro", 60, []), + sectionWithInactiveRoles(template, "tag-1", "tag", 80, ["keys-right", "bass-guitar"]), + sectionWithInactiveRoles(template, "coda-1", "stop", 100, ["bass-guitar"]) + ] + }; + + expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + }); + + it("keeps the selected leftover last-dropout remaining return on tonight's first leftover last-dropout remaining return", () => { + const song = leftoverThenLastReturnThenDropoutThenRemainingThenReturn(); + expect(firstLeftoverLastDropoutRemainingReturn(song, "bass-guitar")).toEqual(namedBassReturn); + expect(firstLeftoverLastDropoutRemainingReturn(song, "keys-right")).toEqual(namedBassReturn); + expect(firstLeftoverLastDropoutRemainingReturn(song, "lead-vocal")).toEqual(namedBassReturn); + expect(firstLeftoverLastDropoutRemainingReturn(song, "missing-role")).toBeNull(); + }); + + it("does not treat leftover last-dropout remaining as leftover last-dropout remaining return", () => { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + const song: RehearsalSong = { + ...seed, + sections: [ + sectionWithInactiveRoles(template, "verse-1", "verse", 0, [ + "bass-guitar", + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "chorus-1", "chorus", 20, [ + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "bridge-1", "bridge", 40, ["lead-vocal"]), + sectionWithInactiveRoles(template, "outro-1", "outro", 60, []), + sectionWithInactiveRoles(template, "tag-1", "tag", 80, ["keys-right", "bass-guitar"]), + sectionWithInactiveRoles(template, "coda-1", "stop", 100, ["bass-guitar"]) + ] + }; + + expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + }); + + it("does not treat leftover last-dropout return as leftover last-dropout remaining return", () => { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + const song: RehearsalSong = { + ...seed, + sections: [ + sectionWithInactiveRoles(template, "verse-1", "verse", 0, [ + "bass-guitar", + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "chorus-1", "chorus", 20, [ + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "bridge-1", "bridge", 40, ["lead-vocal"]), + sectionWithInactiveRoles(template, "outro-1", "outro", 60, []), + sectionWithInactiveRoles(template, "tag-1", "tag", 80, ["keys-right", "bass-guitar"]), + sectionWithInactiveRoles(template, "coda-1", "stop", 100, []) + ] + }; + + expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + }); + + it("does not treat leftover last-dropout as leftover last-dropout remaining return", () => { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + const song: RehearsalSong = { + ...seed, + sections: [ + sectionWithInactiveRoles(template, "verse-1", "verse", 0, [ + "bass-guitar", + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "chorus-1", "chorus", 20, [ + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "bridge-1", "bridge", 40, ["lead-vocal"]), + sectionWithInactiveRoles(template, "outro-1", "outro", 60, []), + sectionWithInactiveRoles(template, "tag-1", "tag", 80, ["keys-right", "bass-guitar"]) + ] + }; + + expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + }); + + it("does not treat leftover last-return as leftover last-dropout remaining return", () => { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + const song: RehearsalSong = { + ...seed, + sections: [ + sectionWithInactiveRoles(template, "verse-1", "verse", 0, [ + "bass-guitar", + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "chorus-1", "chorus", 20, [ + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "bridge-1", "bridge", 40, ["lead-vocal"]), + sectionWithInactiveRoles(template, "outro-1", "outro", 60, []) + ] + }; + + expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + }); + + it("does not treat remaining leftover at leftover return as leftover last-dropout remaining return", () => { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + const song: RehearsalSong = { + ...seed, + sections: [ + sectionWithInactiveRoles(template, "verse-1", "verse", 0, [ + "bass-guitar", + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "chorus-1", "chorus", 20, [ + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "bridge-1", "bridge", 40, ["lead-vocal"]) + ] + }; + + expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + }); + + it("does not treat a come-in without a leftover sit-out as leftover last-dropout remaining return", () => { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + const song: RehearsalSong = { + ...seed, + sections: [ + sectionWithInactiveRoles(template, "verse-1", "verse", 0, ["keys-right"]), + sectionWithInactiveRoles(template, "chorus-1", "chorus", 20, []), + sectionWithInactiveRoles(template, "bridge-1", "bridge", 40, ["bass-guitar"]) + ] + }; + + expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + }); + + it("does not treat a new dropout after remaining leftover as leftover last-dropout remaining return", () => { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + const song: RehearsalSong = { + ...seed, + sections: [ + sectionWithInactiveRoles(template, "verse-1", "verse", 0, [ + "bass-guitar", + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "chorus-1", "chorus", 20, [ + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "bridge-1", "bridge", 40, ["lead-vocal"]), + sectionWithInactiveRoles(template, "outro-1", "outro", 60, ["bass-guitar", "lead-vocal"]) + ] + }; + + expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + }); + + it("ignores inherited is_active evidence", () => { + const song = leftoverThenLastReturnThenDropoutThenRemainingThenReturn(); + const inherited = Object.create({ + is_active: false, + role_id: "keys-right" + }) as RehearsalSong["sections"][number]["partGraph"][number]; + song.sections[0] = { + ...song.sections[0]!, + partGraph: [inherited, ...song.sections[0]!.partGraph] + }; + expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + }); + + it("does not treat a missing is_active flag as leftover-last-dropout-remaining-return evidence", () => { + const song = leftoverThenLastReturnThenDropoutThenRemainingThenReturn(); + song.sections[1] = { + ...song.sections[1]!, + partGraph: song.sections[1]!.partGraph.map((node) => { + if (node.role_id !== "keys-right") { + return node; + } + const rest: Record = { + role_id: node.role_id, + handoff_to: node.handoff_to, + handoff_from: node.handoff_from + }; + return rest as RehearsalSong["sections"][number]["partGraph"][number]; + }) + }; + expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + }); + + it("fails closed on contradictory duplicate graph identities", () => { + const song = leftoverThenLastReturnThenDropoutThenRemainingThenReturn(); + const section = song.sections[6]!; + const bassNode = section.partGraph.find((node) => node.role_id === "bass-guitar")!; + const withoutBass = section.partGraph.filter((node) => node.role_id !== "bass-guitar"); + song.sections[6] = { + ...section, + partGraph: [...withoutBass, { ...bassNode, is_active: true }, { ...bassNode, is_active: false }] + }; + expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + }); + + it("skips blank leftover-last-dropout-remaining-return labels until a named leftover last-dropout remaining return exists", () => { + const song = leftoverThenLastReturnThenDropoutThenRemainingThenReturn(); + song.sections[6] = { + ...song.sections[6]!, + label: "none" as RehearsalSong["sections"][number]["label"] + }; + expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + }); + + it("fails closed when the leftover last-dropout remaining return has no named leftover role", () => { + const song = leftoverThenLastReturnThenDropoutThenRemainingThenReturn(); + song.sections[0] = { + ...song.sections[0]!, + roles: song.sections[0]!.roles.map((role) => ({ ...role, name: " " })) + }; + expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + }); + + it("fails closed when a later section has no named graph", () => { + const song = leftoverThenLastReturnThenDropoutThenRemainingThenReturn(); + song.sections[6] = { + ...song.sections[6]!, + partGraph: [] + }; + expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + }); + + it("fails closed on malformed runtime roots", () => { + for (const malformed of [null, {}, { sections: {} }, { sections: [null] }]) { + expect(firstLeftoverLastDropoutRemainingReturn(malformed as unknown as RehearsalSong)).toBeNull(); + } + }); + + it("isolates blank role ids, non-boolean flags, and unnamed graph members", () => { + const song = leftoverThenLastReturnThenDropoutThenRemainingThenReturn(); + song.sections[0] = { + ...song.sections[0]!, + partGraph: [ + { role_id: " ", is_active: false, handoff_to: [], handoff_from: [] }, + { role_id: "ghost", is_active: false, handoff_to: [], handoff_from: [] }, + { + role_id: "keys-right", + is_active: "no" as unknown as boolean, + handoff_to: [], + handoff_from: [] + }, + ...song.sections[0]!.partGraph + ] + }; + expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + }); +}); + +describe("leftover-last-dropout-remaining-return copy filling", () => { + it("keeps rehearsal values literal", () => { + expect( + fillRangeCopy( + "{returningRoleName} comes back at {sectionLabel} after leftover last-dropout remaining at {remainingSectionLabel}.", + { + returningRoleName: "Bass Guitar {sectionLabel}", + sectionLabel: "ending", + remainingSectionLabel: "stop" + } + ) + ).toBe( + "Bass Guitar {sectionLabel} comes back at ending after leftover last-dropout remaining at stop." + ); + }); +}); diff --git a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.ts b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.ts new file mode 100644 index 000000000..cb7f30b73 --- /dev/null +++ b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.ts @@ -0,0 +1,540 @@ +import type { RehearsalSong } from "@bandscope/shared-types"; +import { meaningfulRangeText } from "./firstRangeSqueeze"; + +/** Tonight's first named leftover last-dropout remaining return after leftover last-dropout remaining. */ +export type FirstLeftoverLastDropoutRemainingReturn = { + sectionLabel: string; + dropoutSectionLabel: string; + lastReturnSectionLabel: string; + remainingSectionLabel: string; + leftoverSectionLabel: string; + fromSectionLabel: string; + remainingRoleId: string; + remainingRoleName: string; + returningRoleId: string; + returningRoleName: string; +}; + +/** Return whether an untrusted runtime value is a plain object record. */ +function isRuntimeObject(value: unknown): value is Record { + return typeof value === "object" && value !== null && !Array.isArray(value); +} + +/** Admit an own-property boolean `is_active` flag. Inherited evidence is isolated. */ +function ownActiveFlag(value: Record): boolean | null { + if (!Object.prototype.hasOwnProperty.call(value, "is_active")) { + return null; + } + if (value.is_active === true) { + return true; + } + if (value.is_active === false) { + return false; + } + return null; +} + +type NamedRoleCatalog = Map; + +/** + * Build trustworthy role identity evidence across the whole song. + * + * Production analysis emits active-only section `roles` while keeping inactive + * identities in `partGraph`. The song-wide catalog therefore lets a leftover + * last-dropout remaining keep its trustworthy display name across leftover + * sit-out, remaining leftover, leftover last-return, leftover last-dropout, + * and leftover last-dropout remaining. + */ +function namedSongRoles(songValue: Record): NamedRoleCatalog | null { + if (!Array.isArray(songValue.sections)) { + return null; + } + + const namedRoles: NamedRoleCatalog = new Map(); + for (const sectionValue of songValue.sections) { + if (!isRuntimeObject(sectionValue) || !Array.isArray(sectionValue.roles)) { + return null; + } + + const sectionRoleIds = new Set(); + for (const roleValue of sectionValue.roles) { + if ( + !isRuntimeObject(roleValue) || + !Object.prototype.hasOwnProperty.call(roleValue, "id") || + !Object.prototype.hasOwnProperty.call(roleValue, "name") + ) { + return null; + } + + const roleId = meaningfulRangeText(roleValue.id); + const roleName = meaningfulRangeText(roleValue.name); + if (!roleId || !roleName || sectionRoleIds.has(roleId)) { + return null; + } + sectionRoleIds.add(roleId); + + const knownName = namedRoles.get(roleId); + if (knownName && knownName !== roleName) { + return null; + } + namedRoles.set(roleId, roleName); + } + } + + return namedRoles.size > 0 ? namedRoles : null; +} + +type NamedGraphNode = { + roleId: string; + active: boolean; +}; + +/** + * Collect one complete, unique activity record for every song-wide named role. + * + * Missing, unknown, duplicate, inherited, or non-boolean graph evidence fails + * closed so a leftover last-dropout cannot be both remaining and returning in + * the same leftover last-dropout remaining decision. + */ +function namedGraphNodes( + sectionValue: Record, + namedRoles: NamedRoleCatalog +): NamedGraphNode[] | null { + if (!Array.isArray(sectionValue.partGraph)) { + return null; + } + + const nodes: NamedGraphNode[] = []; + const seenRoleIds = new Set(); + for (const nodeValue of sectionValue.partGraph) { + if ( + !isRuntimeObject(nodeValue) || + !Object.prototype.hasOwnProperty.call(nodeValue, "role_id") + ) { + return null; + } + + const roleId = meaningfulRangeText(nodeValue.role_id); + if (!roleId || !namedRoles.has(roleId) || seenRoleIds.has(roleId)) { + return null; + } + + const active = ownActiveFlag(nodeValue); + if (active === null) { + return null; + } + + seenRoleIds.add(roleId); + nodes.push({ roleId, active }); + } + + return seenRoleIds.size === namedRoles.size ? nodes : null; +} + +type PendingLeftoverSitOut = { + leftoverSectionLabel: string; + fromSectionLabel: string; + leftoverIds: string[]; + originalSitOutIds: string[]; +}; + +type PendingRemainingLeftover = { + leftoverSectionLabel: string; + remainingSectionLabel: string; + fromSectionLabel: string; + leftoverIds: string[]; + remainingIds: string[]; + originalSitOutIds: string[]; +}; + +type PendingLastReturn = { + leftoverSectionLabel: string; + remainingSectionLabel: string; + lastReturnSectionLabel: string; + fromSectionLabel: string; + leftoverIds: string[]; + remainingIds: string[]; + originalSitOutIds: string[]; + lastRoleId: string; +}; + +type PendingDropout = { + leftoverSectionLabel: string; + remainingSectionLabel: string; + lastReturnSectionLabel: string; + dropoutSectionLabel: string; + fromSectionLabel: string; + leftoverIds: string[]; + remainingIds: string[]; + originalSitOutIds: string[]; + lastRoleId: string; + dropoutIds: string[]; +}; + +type PendingRemainingDropout = { + leftoverSectionLabel: string; + remainingSectionLabel: string; + lastReturnSectionLabel: string; + dropoutSectionLabel: string; + leftoverLastDropoutRemainingSectionLabel: string; + fromSectionLabel: string; + leftoverIds: string[]; + remainingIds: string[]; + originalSitOutIds: string[]; + lastRoleId: string; + dropoutIds: string[]; + leftoverLastDropoutRemainingIds: string[]; + leftoverLastDropoutReturningIds: string[]; +}; + +/** + * Return whether the selected part belongs to this leftover last-dropout remaining return. + * + * A leftover last-dropout remaining return is shown only after leftover last-dropout + * remaining whose original sit-out, leftover, remaining leftover, last leftover, + * leftover last-dropout, or leftover last-dropout remaining cohort includes that + * selected part, so a silent always-active part is never told to count someone in. + */ +function selectedPartBelongs( + pending: PendingDropout | PendingRemainingDropout, + activeRole: string | null +): boolean { + if (!activeRole) { + return true; + } + const leftoverLastDropoutRemainingIds = + "leftoverLastDropoutRemainingIds" in pending ? pending.leftoverLastDropoutRemainingIds : []; + return ( + pending.originalSitOutIds.includes(activeRole) || + pending.leftoverIds.includes(activeRole) || + pending.remainingIds.includes(activeRole) || + pending.lastRoleId === activeRole || + pending.dropoutIds.includes(activeRole) || + leftoverLastDropoutRemainingIds.includes(activeRole) + ); +} + +/** + * Pick the first leftover last-dropout remaining return a player should honor. + * + * A leftover sit-out is the first later named section where at least one member + * of the current reduced cohort has returned and at least one remains out. A + * leftover return with remaining leftover is the first named section after that + * leftover sit-out where at least one leftover part is own-property active and + * at least one leftover remains own-property tacet. A leftover last-return is + * the first later named section where every remaining leftover is own-property + * active. A leftover last-dropout is the first later named section after that + * leftover last-return where at least two named parts are own-property tacet. + * Leftover last-dropout remaining is the first later named section after that + * leftover last-dropout where at least one leftover last-dropout named part is + * own-property active and at least one leftover last-dropout remains + * own-property tacet. A leftover last-dropout remaining return is the first + * later named section after leftover last-dropout remaining where at least one + * leftover last-dropout remaining named part is own-property active. Leftover + * last-dropout remaining itself, leftover last-dropout return with nobody still + * out, leftover last-dropout, leftover last-return, remaining leftover, + * leftover sit-out, leftover return, come-in, tacet, tutti, new dropout after + * remaining leftover, leftover last-dropout remaining without a later remaining + * return, or a singleton leftover last-dropout is not a leftover last-dropout + * remaining return. + * + * Inherited/missing activity, incomplete or contradictory graphs, unnamed + * roles, and malformed runtime data fail closed. When a role is selected, a + * leftover last-dropout remaining return is shown only after leftover + * last-dropout remaining that includes that named part, or leftover + * last-dropout remaining return of that named part. + */ +export function firstLeftoverLastDropoutRemainingReturn( + song: RehearsalSong | unknown, + activeRole: string | null = null +): FirstLeftoverLastDropoutRemainingReturn | null { + if (!isRuntimeObject(song) || !Array.isArray(song.sections)) { + return null; + } + + const namedRoles = namedSongRoles(song); + if (!namedRoles || (activeRole && !namedRoles.has(activeRole))) { + return null; + } + + let reducedFrom: string | null = null; + let sittingOutIds: Set | null = null; + let pendingSitOut: PendingLeftoverSitOut | null = null; + let pendingRemaining: PendingRemainingLeftover | null = null; + let pendingLastReturn: PendingLastReturn | null = null; + let pendingDropout: PendingDropout | null = null; + let pendingRemainingDropout: PendingRemainingDropout | null = null; + + for (const sectionValue of song.sections) { + if (!isRuntimeObject(sectionValue)) { + return null; + } + const sectionLabel = meaningfulRangeText(sectionValue.label); + if (!sectionLabel) { + continue; + } + + const nodes = namedGraphNodes(sectionValue, namedRoles); + if (!nodes) { + return null; + } + + const sittingOut = nodes.filter((node) => node.active === false); + + if (pendingRemainingDropout) { + const remaining = pendingRemainingDropout; + const remainingNodes = remaining.leftoverLastDropoutRemainingIds.map((remainingId) => + nodes.find((node) => node.roleId === remainingId) + ); + if (remainingNodes.some((node) => !node)) { + return null; + } + + const returningRemaining = remainingNodes.filter((node) => node!.active); + const stillRemaining = remainingNodes.filter((node) => node!.active === false); + + if (returningRemaining.length > 0) { + let returning = returningRemaining[0]!; + if (activeRole) { + if (!selectedPartBelongs(remaining, activeRole)) { + continue; + } + const selectedReturning = returningRemaining.find((node) => node!.roleId === activeRole); + if (selectedReturning) { + returning = selectedReturning; + } else if (remaining.leftoverLastDropoutRemainingIds.includes(activeRole) && stillRemaining.some((node) => node!.roleId === activeRole)) { + continue; + } + } + return { + sectionLabel, + remainingSectionLabel: remaining.leftoverLastDropoutRemainingSectionLabel, + dropoutSectionLabel: remaining.dropoutSectionLabel, + lastReturnSectionLabel: remaining.lastReturnSectionLabel, + leftoverSectionLabel: remaining.leftoverSectionLabel, + fromSectionLabel: remaining.fromSectionLabel, + remainingRoleId: returning.roleId, + remainingRoleName: namedRoles.get(returning.roleId)!, + returningRoleId: returning.roleId, + returningRoleName: namedRoles.get(returning.roleId)! + }; + } + continue; + } + + if (pendingDropout) { + const dropout = pendingDropout; + const dropoutNodes = dropout.dropoutIds.map((dropoutId) => + nodes.find((node) => node.roleId === dropoutId) + ); + if (dropoutNodes.some((node) => !node)) { + return null; + } + + const returningDropouts = dropoutNodes.filter((node) => node!.active); + const remainingDropouts = dropoutNodes.filter((node) => node!.active === false); + + if (returningDropouts.length > 0 && remainingDropouts.length > 0) { + if (activeRole && !selectedPartBelongs(dropout, activeRole)) { + continue; + } + pendingRemainingDropout = { + leftoverSectionLabel: dropout.leftoverSectionLabel, + remainingSectionLabel: dropout.remainingSectionLabel, + lastReturnSectionLabel: dropout.lastReturnSectionLabel, + dropoutSectionLabel: dropout.dropoutSectionLabel, + leftoverLastDropoutRemainingSectionLabel: sectionLabel, + fromSectionLabel: dropout.fromSectionLabel, + leftoverIds: dropout.leftoverIds, + remainingIds: dropout.remainingIds, + originalSitOutIds: dropout.originalSitOutIds, + lastRoleId: dropout.lastRoleId, + dropoutIds: dropout.dropoutIds, + leftoverLastDropoutRemainingIds: remainingDropouts.map((node) => node!.roleId), + leftoverLastDropoutReturningIds: returningDropouts.map((node) => node!.roleId) + }; + pendingDropout = null; + continue; + } + + if (returningDropouts.length > 0 && remainingDropouts.length === 0) { + pendingDropout = null; + if (sittingOut.length === 0) { + reducedFrom = null; + sittingOutIds = null; + } else { + reducedFrom = sectionLabel; + sittingOutIds = new Set(sittingOut.map((node) => node.roleId)); + } + } + continue; + } + + if (pendingLastReturn) { + if (sittingOut.length === 0) { + continue; + } + + if (sittingOut.length < 2) { + pendingLastReturn = null; + reducedFrom = sectionLabel; + sittingOutIds = new Set(sittingOut.map((node) => node.roleId)); + continue; + } + + if (activeRole) { + const selectedDropout = sittingOut.find((node) => node.roleId === activeRole); + if ( + !selectedDropout && + !pendingLastReturn.originalSitOutIds.includes(activeRole) && + !pendingLastReturn.leftoverIds.includes(activeRole) && + !pendingLastReturn.remainingIds.includes(activeRole) && + pendingLastReturn.lastRoleId !== activeRole + ) { + continue; + } + } + + pendingDropout = { + leftoverSectionLabel: pendingLastReturn.leftoverSectionLabel, + remainingSectionLabel: pendingLastReturn.remainingSectionLabel, + lastReturnSectionLabel: pendingLastReturn.lastReturnSectionLabel, + dropoutSectionLabel: sectionLabel, + fromSectionLabel: pendingLastReturn.fromSectionLabel, + leftoverIds: pendingLastReturn.leftoverIds, + remainingIds: pendingLastReturn.remainingIds, + originalSitOutIds: pendingLastReturn.originalSitOutIds, + lastRoleId: pendingLastReturn.lastRoleId, + dropoutIds: sittingOut.map((node) => node.roleId) + }; + pendingLastReturn = null; + continue; + } + + if (pendingRemaining) { + const remainingNodes: NamedGraphNode[] = []; + for (const remainingId of pendingRemaining.remainingIds) { + const remainingNode = nodes.find((node) => node.roleId === remainingId); + if (!remainingNode) { + return null; + } + remainingNodes.push(remainingNode); + } + + const returningLast = remainingNodes.filter((node) => node.active); + const stillRemaining = remainingNodes.filter((node) => node.active === false); + + if (returningLast.length > 0 && stillRemaining.length === 0) { + let last = returningLast[0]!; + if (activeRole) { + const activeRoleNode = nodes.find((node) => node.roleId === activeRole); + if (!activeRoleNode) { + return null; + } + const selectedLast = returningLast.find((node) => node.roleId === activeRole); + if (selectedLast) { + last = selectedLast; + } + } + pendingLastReturn = { + leftoverSectionLabel: pendingRemaining.leftoverSectionLabel, + remainingSectionLabel: pendingRemaining.remainingSectionLabel, + lastReturnSectionLabel: sectionLabel, + fromSectionLabel: pendingRemaining.fromSectionLabel, + leftoverIds: pendingRemaining.leftoverIds, + remainingIds: pendingRemaining.remainingIds, + originalSitOutIds: pendingRemaining.originalSitOutIds, + lastRoleId: last.roleId + }; + pendingRemaining = null; + continue; + } + + if (returningLast.length > 0 && stillRemaining.length > 0) { + pendingRemaining = { + leftoverSectionLabel: pendingRemaining.leftoverSectionLabel, + remainingSectionLabel: sectionLabel, + fromSectionLabel: pendingRemaining.fromSectionLabel, + leftoverIds: pendingRemaining.leftoverIds, + remainingIds: stillRemaining.map((node) => node.roleId), + originalSitOutIds: pendingRemaining.originalSitOutIds + }; + } + continue; + } + + if (pendingSitOut) { + const leftoverNodes = pendingSitOut.leftoverIds.map((leftoverId) => + nodes.find((node) => node.roleId === leftoverId) + ); + if (leftoverNodes.some((node) => !node)) { + return null; + } + + const returningLeftovers = leftoverNodes.filter((node) => node!.active); + const remainingLeftovers = leftoverNodes.filter((node) => node!.active === false); + + if (returningLeftovers.length > 0 && remainingLeftovers.length > 0) { + pendingRemaining = { + leftoverSectionLabel: pendingSitOut.leftoverSectionLabel, + remainingSectionLabel: sectionLabel, + fromSectionLabel: pendingSitOut.fromSectionLabel, + leftoverIds: pendingSitOut.leftoverIds, + remainingIds: remainingLeftovers.map((node) => node!.roleId), + originalSitOutIds: pendingSitOut.originalSitOutIds + }; + pendingSitOut = null; + continue; + } + + if (returningLeftovers.length > 0 && remainingLeftovers.length === 0) { + pendingSitOut = null; + if (sittingOut.length === 0) { + reducedFrom = null; + sittingOutIds = null; + } else { + reducedFrom = sectionLabel; + sittingOutIds = new Set(sittingOut.map((node) => node.roleId)); + } + } + continue; + } + + if (!sittingOutIds || !reducedFrom) { + if (sittingOut.length === 0) { + continue; + } + reducedFrom = sectionLabel; + sittingOutIds = new Set(sittingOut.map((node) => node.roleId)); + continue; + } + + const baselineIds = sittingOutIds; + const returning = nodes.filter( + (node) => node.active === true && baselineIds.has(node.roleId) + ); + const leftovers = sittingOut.filter((node) => baselineIds.has(node.roleId)); + + if (returning.length > 0 && leftovers.length > 0) { + pendingSitOut = { + leftoverSectionLabel: sectionLabel, + fromSectionLabel: reducedFrom, + leftoverIds: leftovers.map((node) => node.roleId), + originalSitOutIds: [...baselineIds] + }; + continue; + } + + if (returning.length === baselineIds.size && leftovers.length === 0) { + if (sittingOut.length === 0) { + reducedFrom = null; + sittingOutIds = null; + } else { + reducedFrom = sectionLabel; + sittingOutIds = new Set(sittingOut.map((node) => node.roleId)); + } + } + } + + return null; +} diff --git a/apps/desktop/src/locales/en/common.json b/apps/desktop/src/locales/en/common.json index d803a765e..b67fd657c 100644 --- a/apps/desktop/src/locales/en/common.json +++ b/apps/desktop/src/locales/en/common.json @@ -153,6 +153,10 @@ "workspaceFirstRangeCheck": "{roleName} sits {lowestNote}–{highestNote} in {sectionLabel}. Check that span on your instrument before the {sectionLabel}.", "workspaceFirstRangeClash": "{roleName} sits {lowestNote}–{highestNote} in {sectionLabel}. Hear that clash on your instrument before the {sectionLabel}.", "workspaceFirstRangeMissing": "Tonight's first range still needs an ear check. Confirm the high and low notes on the selected part before the first section.", + "workspaceFirstLeftoverLastDropoutRemainingReturnTitle": "Tonight's first leftover last-dropout remaining return", + "workspaceFirstLeftoverLastDropoutRemainingReturnNamed": "{returningRoleName} comes back at {sectionLabel} after staying out through leftover last-dropout remaining at {remainingSectionLabel}. Count {returningRoleName} in from the top of {sectionLabel}.", + "workspaceFirstLeftoverLastDropoutRemainingReturnComeIn": "{returningRoleName} comes back at {sectionLabel} after staying out through leftover last-dropout remaining at {remainingSectionLabel}. Come back from leftover last-dropout remaining at the top of {sectionLabel}.", + "workspaceFirstLeftoverLastDropoutRemainingReturnMissing": "Tonight's first leftover last-dropout remaining return still needs a named leftover last-dropout remaining and a later remaining return. Confirm who comes back after leftover last-dropout remaining before the first section.", "sectionRangeLabel": "Range", "sectionRangeNextAction": "Check this span on your instrument before {sectionLabel}." } diff --git a/apps/desktop/src/locales/ko/common.json b/apps/desktop/src/locales/ko/common.json index 0f6c6c66d..e0b76d492 100644 --- a/apps/desktop/src/locales/ko/common.json +++ b/apps/desktop/src/locales/ko/common.json @@ -153,6 +153,10 @@ "workspaceFirstRangeCheck": "{sectionLabel}의 {roleName}은 {lowestNote}–{highestNote}입니다. {sectionLabel} 들어가기 전에 그 음역을 악기로 확인해 보세요.", "workspaceFirstRangeClash": "{sectionLabel}의 {roleName}은 {lowestNote}–{highestNote}이고 다른 파트와 겹칩니다. {sectionLabel} 들어가기 전에 그 충돌을 악기로 들어 보세요.", "workspaceFirstRangeMissing": "오늘 먼저 볼 음역은 아직 귀로 확인이 필요합니다. 선택한 파트의 최저·최고음을 첫 구간 전에 확인해 보세요.", + "workspaceFirstLeftoverLastDropoutRemainingReturnTitle": "오늘 먼저 마지막 복귀 후 쉬는 자리 중 남는 자리의 복귀", + "workspaceFirstLeftoverLastDropoutRemainingReturnNamed": "{returningRoleName}은 {remainingSectionLabel}에서 마지막 복귀 후 쉬는 자리 중 남는 자리로 쉰 뒤 {sectionLabel}에서 들어옵니다. {sectionLabel} 처음부터 {returningRoleName}을 넣어 두세요.", + "workspaceFirstLeftoverLastDropoutRemainingReturnComeIn": "{returningRoleName}은 {remainingSectionLabel}에서 마지막 복귀 후 쉬는 자리 중 남는 자리로 쉰 뒤 {sectionLabel}에서 들어옵니다. {sectionLabel} 처음부터 들어오세요.", + "workspaceFirstLeftoverLastDropoutRemainingReturnMissing": "오늘 먼저 마지막 복귀 후 쉬는 자리 중 남는 자리의 복귀는 아직 확인이 필요합니다. 마지막 복귀 후 쉬는 자리 중 남는 파트 중 누가 다시 들어오는지 첫 구간 전에 확인하세요.", "sectionRangeLabel": "음역", "sectionRangeNextAction": "{sectionLabel} 들어가기 전에 이 음역을 악기로 확인해 보세요." } diff --git a/docs/design-system/component-contract.md b/docs/design-system/component-contract.md index 22602c313..b60a6768d 100644 --- a/docs/design-system/component-contract.md +++ b/docs/design-system/component-contract.md @@ -80,6 +80,7 @@ The authoritative Figma view is `31 Component Contract Catalog`. This file mirro - `LoadingState` keeps `role="status"`, `aria-live="polite"`, `aria-atomic="true"`, and `aria-busy="true"`. - `ErrorState` keeps `role="alert"`, `aria-live="assertive"`, and visible safe error detail copy. - `EmptyState` must remain an actionable state card, not a blank placeholder panel. +- Ready `Workspace` names tonight's first playable range and tonight's first leftover last-dropout remaining return so the map enables the next rehearsal action without opening files or export paths. - If a new workspace state is added in code, update Figma page 34 and page 33 audit evidence before merging. ## Pattern Backlog diff --git a/docs/doctoring/first-leftover-last-dropout-remaining-return.md b/docs/doctoring/first-leftover-last-dropout-remaining-return.md new file mode 100644 index 000000000..655bd0c67 --- /dev/null +++ b/docs/doctoring/first-leftover-last-dropout-remaining-return.md @@ -0,0 +1,18 @@ +# Tonight's first leftover last-dropout remaining return + +The ready rehearsal map names the first leftover last-dropout remaining return from existing `partGraph` evidence: a named leftover sit-out, then a later named leftover return where at least one leftover named part is own-property active and at least one leftover remains own-property tacet, then a later named leftover last-return where every remaining leftover is own-property active, then a later named leftover last-dropout where at least two named parts are own-property tacet, then a later named leftover last-dropout remaining where at least one leftover last-dropout named part is own-property active and at least one leftover last-dropout remains own-property tacet, then a later named leftover last-dropout remaining return where at least one leftover last-dropout remaining named part is own-property active. This is who comes back after staying out through leftover last-dropout remaining. It is not leftover last-dropout remaining, leftover last-dropout return with nobody still out, leftover last-dropout, leftover last-return, remaining leftover, leftover sit-out, leftover return, come-in, tacet, tutti, Fine, last-line breath, a singleton leftover last-dropout, leftover last-dropout remaining without a later remaining return, a new dropout after remaining leftover, or a new MIR product. + +## Next action + +- Named leftover last-dropout remaining return: come back from leftover last-dropout remaining at the named return. +- Named returning or other included part: count the leftover last-dropout remaining in from the top of that return. +- Missing: confirm who comes back after leftover last-dropout remaining before the first section. + +## Security Notes + +- Untrusted inputs: `RehearsalSong` JSON, section labels, `partGraph` nodes, `is_active`, role ids, and role names from analysis or a reopened project. +- Trust boundary: this helper never opens files, URLs, IPC, WebView, subprocesses, model artifacts, or export paths. It only admits an own-property leftover sit-out, leftover return with remaining leftover, leftover last-return, leftover last-dropout cohort of at least two named parts, leftover last-dropout remaining, and a later named leftover last-dropout remaining return where at least one leftover last-dropout remaining named part is own-property active. +- Allowlist: section labels and role names must be meaningful text. A missing graph node is not leftover last-dropout remaining return. Inherited `is_active` is isolated. Leftover last-dropout remaining is leftover last-dropout remaining, not leftover last-dropout remaining return. A leftover last-dropout return with nobody still out is leftover last-dropout return, not leftover last-dropout remaining return. When a role is selected, only leftover last-dropout remaining return after leftover last-dropout remaining that includes that named part, or leftover last-dropout remaining return of that named part, is shown. +- Safe failure: inherited flags, blank labels, missing names, leftover last-dropout remaining without a later remaining return, leftover last-dropout returns with nobody still out, leftover last-dropouts, leftover last-returns, remaining leftovers, come-ins, unnamed roles, empty graphs, and malformed roots return `null` so the workspace shows the missing-copy next action instead of crashing or inventing leftover last-dropout remaining return. +- Logging/privacy: rejected or accepted leftover last-dropout remaining return cues are not logged. Copy interpolation keeps rehearsal values literal. +- Tests: `firstLeftoverLastDropoutRemainingReturn.test.ts` and the Workspace callout cover the demo all-active case, an explicit bass leftover last-dropout remaining return after leftover last-dropout remaining, selected-role scoping, inherited flags, missing `is_active`, leftover last-dropout remaining without later remaining return, leftover last-dropout returns, leftover last-dropouts, leftover last-returns, remaining leftovers, come-ins, unnamed roles, empty graphs, and literal copy filling. From ed3ea2d417479b905f33922974af19747ad61f47 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Mon, 31 Aug 2026 21:26:10 +0900 Subject: [PATCH 02/13] test(workspace): preserve last-return across singleton dropout --- ...tRemainingReturn.singleton-dropout.test.ts | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.singleton-dropout.test.ts diff --git a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.singleton-dropout.test.ts b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.singleton-dropout.test.ts new file mode 100644 index 000000000..5db6967b9 --- /dev/null +++ b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.singleton-dropout.test.ts @@ -0,0 +1,66 @@ +import { createDemoRehearsalSong, type RehearsalSong } from "@bandscope/shared-types"; +import { describe, expect, it } from "vitest"; +import { firstLeftoverLastDropoutRemainingReturn } from "./firstLeftoverLastDropoutRemainingReturn"; + +function sectionWithInactiveRoles( + template: RehearsalSong["sections"][number], + id: string, + label: string, + start: number, + inactiveRoleIds: readonly string[] +): RehearsalSong["sections"][number] { + const inactive = new Set(inactiveRoleIds); + return { + ...template, + id, + label: label as RehearsalSong["sections"][number]["label"], + timeRange: { start, end: start + 20 }, + partGraph: template.partGraph.map((node) => ({ + ...node, + is_active: !inactive.has(node.role_id) + })) + }; +} + +describe("firstLeftoverLastDropoutRemainingReturn singleton dropout provenance", () => { + it("keeps the completed leftover sequence while a singleton dropout grows into a valid cohort", () => { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + const song: RehearsalSong = { + ...seed, + sections: [ + sectionWithInactiveRoles(template, "verse-1", "verse", 0, [ + "bass-guitar", + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "chorus-1", "chorus", 20, [ + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "bridge-1", "bridge", 40, ["lead-vocal"]), + sectionWithInactiveRoles(template, "outro-1", "outro", 60, []), + sectionWithInactiveRoles(template, "pickup-1", "pickup", 80, ["bass-guitar"]), + sectionWithInactiveRoles(template, "tag-1", "tag", 100, [ + "bass-guitar", + "keys-right" + ]), + sectionWithInactiveRoles(template, "coda-1", "coda", 120, ["bass-guitar"]), + sectionWithInactiveRoles(template, "ending-1", "ending", 140, []) + ] + }; + + expect(firstLeftoverLastDropoutRemainingReturn(song)).toEqual({ + sectionLabel: "ending", + remainingSectionLabel: "coda", + dropoutSectionLabel: "tag", + lastReturnSectionLabel: "outro", + leftoverSectionLabel: "chorus", + fromSectionLabel: "verse", + remainingRoleId: "bass-guitar", + remainingRoleName: "Bass Guitar", + returningRoleId: "bass-guitar", + returningRoleName: "Bass Guitar" + }); + }); +}); From 5311565015d1c15f75ae3125c88d5b0ec4297bce Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Tue, 1 Sep 2026 01:43:08 +0900 Subject: [PATCH 03/13] fix(workspace): retain last-return across singleton dropout --- .../workspace/firstLeftoverLastDropoutRemainingReturn.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.ts b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.ts index cb7f30b73..ba5f87cf3 100644 --- a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.ts +++ b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.ts @@ -376,9 +376,6 @@ export function firstLeftoverLastDropoutRemainingReturn( } if (sittingOut.length < 2) { - pendingLastReturn = null; - reducedFrom = sectionLabel; - sittingOutIds = new Set(sittingOut.map((node) => node.roleId)); continue; } From 55c3e315da2735d3119ca128c69cf090f7ab9b38 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Tue, 1 Sep 2026 04:04:50 +0900 Subject: [PATCH 04/13] docs(test): explain selected-role activity fixture --- ...rstLeftoverLastDropoutRemainingReturn.selected-role.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.selected-role.test.ts b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.selected-role.test.ts index ce81eaffe..d83f38458 100644 --- a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.selected-role.test.ts +++ b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.selected-role.test.ts @@ -2,6 +2,7 @@ import { createDemoRehearsalSong, type RehearsalSong } from "@bandscope/shared-t import { describe, expect, it } from "vitest"; import { firstLeftoverLastDropoutRemainingReturn } from "./firstLeftoverLastDropoutRemainingReturn"; +/** Build a timeline section whose activity graph marks only the supplied roles inactive. */ function sectionWithInactiveRoles( template: RehearsalSong["sections"][number], id: string, @@ -130,4 +131,4 @@ describe("firstLeftoverLastDropoutRemainingReturn selected-role search", () => { expect(firstLeftoverLastDropoutRemainingReturn(song, "always-active")).toBeNull(); }); -}); +}); \ No newline at end of file From 946ceac17a1e56427e8ded24734876408f711ce9 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Tue, 1 Sep 2026 04:05:10 +0900 Subject: [PATCH 05/13] docs(test): explain singleton-dropout activity fixture --- ...tLeftoverLastDropoutRemainingReturn.singleton-dropout.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.singleton-dropout.test.ts b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.singleton-dropout.test.ts index 5db6967b9..9db3ba5a5 100644 --- a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.singleton-dropout.test.ts +++ b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.singleton-dropout.test.ts @@ -2,6 +2,7 @@ import { createDemoRehearsalSong, type RehearsalSong } from "@bandscope/shared-t import { describe, expect, it } from "vitest"; import { firstLeftoverLastDropoutRemainingReturn } from "./firstLeftoverLastDropoutRemainingReturn"; +/** Build a section fixture that keeps role identity stable while changing only activity evidence. */ function sectionWithInactiveRoles( template: RehearsalSong["sections"][number], id: string, From 071cdbd29e50ec8c130b2a24fafe351083e1337e Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Tue, 1 Sep 2026 06:35:58 +0900 Subject: [PATCH 06/13] test(workspace): reject ambiguous simultaneous remaining returns --- ...emainingReturn.simultaneous-return.test.ts | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.simultaneous-return.test.ts diff --git a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.simultaneous-return.test.ts b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.simultaneous-return.test.ts new file mode 100644 index 000000000..1d753c869 --- /dev/null +++ b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.simultaneous-return.test.ts @@ -0,0 +1,59 @@ +import { createDemoRehearsalSong, type RehearsalSong } from "@bandscope/shared-types"; +import { describe, expect, it } from "vitest"; +import { firstLeftoverLastDropoutRemainingReturn } from "./firstLeftoverLastDropoutRemainingReturn"; + +/** Build a section fixture that keeps role identity stable while changing only activity evidence. */ +function sectionWithInactiveRoles( + template: RehearsalSong["sections"][number], + id: string, + label: string, + start: number, + inactiveRoleIds: readonly string[] +): RehearsalSong["sections"][number] { + const inactive = new Set(inactiveRoleIds); + return { + ...template, + id, + label: label as RehearsalSong["sections"][number]["label"], + timeRange: { start, end: start + 20 }, + partGraph: template.partGraph.map((node) => ({ + ...node, + is_active: !inactive.has(node.role_id) + })) + }; +} + +describe("firstLeftoverLastDropoutRemainingReturn simultaneous return", () => { + it("fails closed when multiple still-out roles return together", () => { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + const song: RehearsalSong = { + ...seed, + sections: [ + sectionWithInactiveRoles(template, "verse-1", "verse", 0, [ + "bass-guitar", + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "chorus-1", "chorus", 20, [ + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "bridge-1", "bridge", 40, ["lead-vocal"]), + sectionWithInactiveRoles(template, "outro-1", "outro", 60, []), + sectionWithInactiveRoles(template, "tag-1", "tag", 80, [ + "bass-guitar", + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "coda-1", "coda", 100, [ + "bass-guitar", + "keys-right" + ]), + sectionWithInactiveRoles(template, "ending-1", "ending", 120, []) + ] + }; + + expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + }); +}); From a66400f4a28f75755948a5371670b3cac2f03061 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Tue, 1 Sep 2026 06:38:33 +0900 Subject: [PATCH 07/13] test(workspace): cover simultaneous return disambiguation --- ...emainingReturn.simultaneous-return.test.ts | 86 ++++++++++++------- 1 file changed, 56 insertions(+), 30 deletions(-) diff --git a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.simultaneous-return.test.ts b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.simultaneous-return.test.ts index 1d753c869..b941c32ff 100644 --- a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.simultaneous-return.test.ts +++ b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.simultaneous-return.test.ts @@ -23,37 +23,63 @@ function sectionWithInactiveRoles( }; } +/** Build a sequence whose final two still-out roles return in the same section. */ +function simultaneousRemainingReturnSong(): RehearsalSong { + const seed = createDemoRehearsalSong(); + const template = seed.sections[0]!; + return { + ...seed, + sections: [ + sectionWithInactiveRoles(template, "verse-1", "verse", 0, [ + "bass-guitar", + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "chorus-1", "chorus", 20, [ + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "bridge-1", "bridge", 40, ["lead-vocal"]), + sectionWithInactiveRoles(template, "outro-1", "outro", 60, []), + sectionWithInactiveRoles(template, "tag-1", "tag", 80, [ + "bass-guitar", + "keys-right", + "lead-vocal" + ]), + sectionWithInactiveRoles(template, "coda-1", "coda", 100, [ + "bass-guitar", + "keys-right" + ]), + sectionWithInactiveRoles(template, "ending-1", "ending", 120, []) + ] + }; +} + describe("firstLeftoverLastDropoutRemainingReturn simultaneous return", () => { - it("fails closed when multiple still-out roles return together", () => { - const seed = createDemoRehearsalSong(); - const template = seed.sections[0]!; - const song: RehearsalSong = { - ...seed, - sections: [ - sectionWithInactiveRoles(template, "verse-1", "verse", 0, [ - "bass-guitar", - "keys-right", - "lead-vocal" - ]), - sectionWithInactiveRoles(template, "chorus-1", "chorus", 20, [ - "keys-right", - "lead-vocal" - ]), - sectionWithInactiveRoles(template, "bridge-1", "bridge", 40, ["lead-vocal"]), - sectionWithInactiveRoles(template, "outro-1", "outro", 60, []), - sectionWithInactiveRoles(template, "tag-1", "tag", 80, [ - "bass-guitar", - "keys-right", - "lead-vocal" - ]), - sectionWithInactiveRoles(template, "coda-1", "coda", 100, [ - "bass-guitar", - "keys-right" - ]), - sectionWithInactiveRoles(template, "ending-1", "ending", 120, []) - ] - }; + it("fails closed when multiple still-out roles return together without a selected role", () => { + expect(firstLeftoverLastDropoutRemainingReturn(simultaneousRemainingReturnSong())).toBeNull(); + }); + + it("returns the selected role when that role is one of simultaneous returners", () => { + expect( + firstLeftoverLastDropoutRemainingReturn(simultaneousRemainingReturnSong(), "keys-right") + ).toEqual({ + sectionLabel: "ending", + remainingSectionLabel: "coda", + dropoutSectionLabel: "tag", + lastReturnSectionLabel: "outro", + leftoverSectionLabel: "chorus", + fromSectionLabel: "verse", + remainingRoleId: "keys-right", + remainingRoleName: "Keys (Right Hand)", + returningRoleId: "keys-right", + returningRoleName: "Keys (Right Hand)" + }); + }); - expect(firstLeftoverLastDropoutRemainingReturn(song)).toBeNull(); + it("fails closed when the selected role cannot disambiguate simultaneous returners", () => { + expect( + firstLeftoverLastDropoutRemainingReturn(simultaneousRemainingReturnSong(), "lead-vocal") + ).toBeNull(); }); }); From 4fa93e40fb2e6cf68f3270c3f7236d17e80005e3 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Tue, 1 Sep 2026 06:39:25 +0900 Subject: [PATCH 08/13] fix(workspace): fail closed on ambiguous simultaneous returns --- .../workspace/firstLeftoverLastDropoutRemainingReturn.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.ts b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.ts index ba5f87cf3..aaeb7b26c 100644 --- a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.ts +++ b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.ts @@ -302,9 +302,16 @@ export function firstLeftoverLastDropoutRemainingReturn( const selectedReturning = returningRemaining.find((node) => node!.roleId === activeRole); if (selectedReturning) { returning = selectedReturning; - } else if (remaining.leftoverLastDropoutRemainingIds.includes(activeRole) && stillRemaining.some((node) => node!.roleId === activeRole)) { + } else if ( + remaining.leftoverLastDropoutRemainingIds.includes(activeRole) && + stillRemaining.some((node) => node!.roleId === activeRole) + ) { continue; + } else if (returningRemaining.length > 1) { + return null; } + } else if (returningRemaining.length > 1) { + return null; } return { sectionLabel, From edb1187ddc8a4bae77a48c52bb0cb4e7b86e5ee0 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Tue, 1 Sep 2026 06:41:25 +0900 Subject: [PATCH 09/13] test(workspace): match canonical demo role identity --- ...overLastDropoutRemainingReturn.simultaneous-return.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.simultaneous-return.test.ts b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.simultaneous-return.test.ts index b941c32ff..6d5581fb9 100644 --- a/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.simultaneous-return.test.ts +++ b/apps/desktop/src/features/workspace/firstLeftoverLastDropoutRemainingReturn.simultaneous-return.test.ts @@ -71,9 +71,9 @@ describe("firstLeftoverLastDropoutRemainingReturn simultaneous return", () => { leftoverSectionLabel: "chorus", fromSectionLabel: "verse", remainingRoleId: "keys-right", - remainingRoleName: "Keys (Right Hand)", + remainingRoleName: "Keyboard 1 Right Hand", returningRoleId: "keys-right", - returningRoleName: "Keys (Right Hand)" + returningRoleName: "Keyboard 1 Right Hand" }); }); From faf03aeb6a2b3bf2fe592478547f7205b5af2600 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Tue, 1 Sep 2026 07:11:18 +0900 Subject: [PATCH 10/13] test(i18n): require rehearsal-language return copy --- .../src/i18n/rehearsalReturnCopy.test.ts | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 apps/desktop/src/i18n/rehearsalReturnCopy.test.ts diff --git a/apps/desktop/src/i18n/rehearsalReturnCopy.test.ts b/apps/desktop/src/i18n/rehearsalReturnCopy.test.ts new file mode 100644 index 000000000..c5bcb151d --- /dev/null +++ b/apps/desktop/src/i18n/rehearsalReturnCopy.test.ts @@ -0,0 +1,43 @@ +import { describe, expect, it } from "vitest"; +import { createTranslator } from "./index"; + +const COPY_KEYS = [ + "workspaceFirstLeftoverLastDropoutRemainingReturnTitle", + "workspaceFirstLeftoverLastDropoutRemainingReturnNamed", + "workspaceFirstLeftoverLastDropoutRemainingReturnComeIn", + "workspaceFirstLeftoverLastDropoutRemainingReturnMissing" +] as const; + +describe("rehearsal return copy", () => { + it("keeps English customer copy in rehearsal language instead of state-machine terms", () => { + const t = createTranslator("en"); + + expect(t(COPY_KEYS[0])).toBe("Next part back in"); + expect(t(COPY_KEYS[1])).toBe( + "{returningRoleName} comes back at {sectionLabel} after sitting out at {remainingSectionLabel}. Count {returningRoleName} in from the top of {sectionLabel}." + ); + expect(t(COPY_KEYS[2])).toBe( + "{returningRoleName} comes back at {sectionLabel} after sitting out at {remainingSectionLabel}. Come in from the top of {sectionLabel}." + ); + expect(t(COPY_KEYS[3])).toBe( + "The next return is not clear yet. Confirm which part comes back after parts drop out before rehearsal." + ); + expect(COPY_KEYS.map((key) => t(key)).join(" ").toLowerCase()).not.toContain("leftover"); + expect(COPY_KEYS.map((key) => t(key)).join(" ").toLowerCase()).not.toContain("last-dropout"); + }); + + it("keeps Korean customer copy focused on the player's next action", () => { + const t = createTranslator("ko"); + + expect(t(COPY_KEYS[0])).toBe("다음에 다시 들어올 파트"); + expect(t(COPY_KEYS[1])).toBe( + "{returningRoleName}은 {remainingSectionLabel}에서 쉰 뒤 {sectionLabel} 처음에 다시 들어옵니다. {sectionLabel} 첫 박부터 {returningRoleName}을 함께 세어 주세요." + ); + expect(t(COPY_KEYS[2])).toBe( + "{returningRoleName}은 {remainingSectionLabel}에서 쉰 뒤 {sectionLabel} 처음에 다시 들어옵니다. {sectionLabel} 첫 박부터 들어오세요." + ); + expect(t(COPY_KEYS[3])).toBe( + "다음 복귀 파트가 아직 명확하지 않습니다. 다음에 파트가 빠진 뒤 누가 다시 들어오는지 합주 전에 확인하세요." + ); + }); +}); From b8f2dec70e7d769d0fba8107254cf4f0d1ca0b83 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Tue, 1 Sep 2026 07:11:58 +0900 Subject: [PATCH 11/13] fix(copy): make rehearsal return cue player-readable --- apps/desktop/src/locales/en/common.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/desktop/src/locales/en/common.json b/apps/desktop/src/locales/en/common.json index b67fd657c..5cbc45e02 100644 --- a/apps/desktop/src/locales/en/common.json +++ b/apps/desktop/src/locales/en/common.json @@ -153,10 +153,10 @@ "workspaceFirstRangeCheck": "{roleName} sits {lowestNote}–{highestNote} in {sectionLabel}. Check that span on your instrument before the {sectionLabel}.", "workspaceFirstRangeClash": "{roleName} sits {lowestNote}–{highestNote} in {sectionLabel}. Hear that clash on your instrument before the {sectionLabel}.", "workspaceFirstRangeMissing": "Tonight's first range still needs an ear check. Confirm the high and low notes on the selected part before the first section.", - "workspaceFirstLeftoverLastDropoutRemainingReturnTitle": "Tonight's first leftover last-dropout remaining return", - "workspaceFirstLeftoverLastDropoutRemainingReturnNamed": "{returningRoleName} comes back at {sectionLabel} after staying out through leftover last-dropout remaining at {remainingSectionLabel}. Count {returningRoleName} in from the top of {sectionLabel}.", - "workspaceFirstLeftoverLastDropoutRemainingReturnComeIn": "{returningRoleName} comes back at {sectionLabel} after staying out through leftover last-dropout remaining at {remainingSectionLabel}. Come back from leftover last-dropout remaining at the top of {sectionLabel}.", - "workspaceFirstLeftoverLastDropoutRemainingReturnMissing": "Tonight's first leftover last-dropout remaining return still needs a named leftover last-dropout remaining and a later remaining return. Confirm who comes back after leftover last-dropout remaining before the first section.", + "workspaceFirstLeftoverLastDropoutRemainingReturnTitle": "Next part back in", + "workspaceFirstLeftoverLastDropoutRemainingReturnNamed": "{returningRoleName} comes back at {sectionLabel} after sitting out at {remainingSectionLabel}. Count {returningRoleName} in from the top of {sectionLabel}.", + "workspaceFirstLeftoverLastDropoutRemainingReturnComeIn": "{returningRoleName} comes back at {sectionLabel} after sitting out at {remainingSectionLabel}. Come in from the top of {sectionLabel}.", + "workspaceFirstLeftoverLastDropoutRemainingReturnMissing": "The next return is not clear yet. Confirm which part comes back after parts drop out before rehearsal.", "sectionRangeLabel": "Range", "sectionRangeNextAction": "Check this span on your instrument before {sectionLabel}." } From baf30bf5aa3c089bc21d489c1c447f757b390139 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Tue, 1 Sep 2026 07:12:23 +0900 Subject: [PATCH 12/13] fix(copy): localize return cue as a rehearsal action --- apps/desktop/src/locales/ko/common.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/desktop/src/locales/ko/common.json b/apps/desktop/src/locales/ko/common.json index e0b76d492..16b938373 100644 --- a/apps/desktop/src/locales/ko/common.json +++ b/apps/desktop/src/locales/ko/common.json @@ -153,10 +153,10 @@ "workspaceFirstRangeCheck": "{sectionLabel}의 {roleName}은 {lowestNote}–{highestNote}입니다. {sectionLabel} 들어가기 전에 그 음역을 악기로 확인해 보세요.", "workspaceFirstRangeClash": "{sectionLabel}의 {roleName}은 {lowestNote}–{highestNote}이고 다른 파트와 겹칩니다. {sectionLabel} 들어가기 전에 그 충돌을 악기로 들어 보세요.", "workspaceFirstRangeMissing": "오늘 먼저 볼 음역은 아직 귀로 확인이 필요합니다. 선택한 파트의 최저·최고음을 첫 구간 전에 확인해 보세요.", - "workspaceFirstLeftoverLastDropoutRemainingReturnTitle": "오늘 먼저 마지막 복귀 후 쉬는 자리 중 남는 자리의 복귀", - "workspaceFirstLeftoverLastDropoutRemainingReturnNamed": "{returningRoleName}은 {remainingSectionLabel}에서 마지막 복귀 후 쉬는 자리 중 남는 자리로 쉰 뒤 {sectionLabel}에서 들어옵니다. {sectionLabel} 처음부터 {returningRoleName}을 넣어 두세요.", - "workspaceFirstLeftoverLastDropoutRemainingReturnComeIn": "{returningRoleName}은 {remainingSectionLabel}에서 마지막 복귀 후 쉬는 자리 중 남는 자리로 쉰 뒤 {sectionLabel}에서 들어옵니다. {sectionLabel} 처음부터 들어오세요.", - "workspaceFirstLeftoverLastDropoutRemainingReturnMissing": "오늘 먼저 마지막 복귀 후 쉬는 자리 중 남는 자리의 복귀는 아직 확인이 필요합니다. 마지막 복귀 후 쉬는 자리 중 남는 파트 중 누가 다시 들어오는지 첫 구간 전에 확인하세요.", + "workspaceFirstLeftoverLastDropoutRemainingReturnTitle": "다음에 다시 들어올 파트", + "workspaceFirstLeftoverLastDropoutRemainingReturnNamed": "{returningRoleName}은 {remainingSectionLabel}에서 쉰 뒤 {sectionLabel} 처음에 다시 들어옵니다. {sectionLabel} 첫 박부터 {returningRoleName}을 함께 세어 주세요.", + "workspaceFirstLeftoverLastDropoutRemainingReturnComeIn": "{returningRoleName}은 {remainingSectionLabel}에서 쉰 뒤 {sectionLabel} 처음에 다시 들어옵니다. {sectionLabel} 첫 박부터 들어오세요.", + "workspaceFirstLeftoverLastDropoutRemainingReturnMissing": "다음 복귀 파트가 아직 명확하지 않습니다. 다음에 파트가 빠진 뒤 누가 다시 들어오는지 합주 전에 확인하세요.", "sectionRangeLabel": "음역", "sectionRangeNextAction": "{sectionLabel} 들어가기 전에 이 음역을 악기로 확인해 보세요." } From 98b01c9b2375d02b9a16a465ac38f560ef883c32 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Tue, 1 Sep 2026 07:15:17 +0900 Subject: [PATCH 13/13] test(workspace): match player-readable return copy --- .../src/features/workspace/Workspace.test.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/desktop/src/features/workspace/Workspace.test.tsx b/apps/desktop/src/features/workspace/Workspace.test.tsx index 4877dff1b..6c09387e5 100644 --- a/apps/desktop/src/features/workspace/Workspace.test.tsx +++ b/apps/desktop/src/features/workspace/Workspace.test.tsx @@ -140,7 +140,7 @@ describe("Workspace", () => { expect(screen.getByText(/Verse harmony pass/i)).toBeTruthy(); }); - it("names tonight's first leftover last-dropout remaining return after leftover last-dropout remaining", () => { + it("names the next part back in and gives the band a count-in action", () => { setNavigatorLanguage("en-US"); const song = createDemoRehearsalSong(); const verse = song.sections[0]!; @@ -227,13 +227,13 @@ describe("Workspace", () => { render(); const callout = screen.getByTestId("first-leftover-last-dropout-remaining-return"); - expect(callout).toHaveTextContent("Tonight's first leftover last-dropout remaining return"); + expect(callout).toHaveTextContent("Next part back in"); expect(callout).toHaveTextContent( - "Bass Guitar comes back at ending after staying out through leftover last-dropout remaining at stop. Count Bass Guitar in from the top of ending." + "Bass Guitar comes back at ending after sitting out at stop. Count Bass Guitar in from the top of ending." ); }); - it("tells the leftover last-dropout remaining return to come back after leftover last-dropout remaining", () => { + it("tells the selected returning player where to come back in", () => { setNavigatorLanguage("en-US"); const song = createDemoRehearsalSong(); const verse = song.sections[0]!; @@ -321,18 +321,18 @@ describe("Workspace", () => { fireEvent.click(screen.getByRole("tab", { name: "Bass Guitar" })); expect(screen.getByTestId("first-leftover-last-dropout-remaining-return")).toHaveTextContent( - "Bass Guitar comes back at ending after staying out through leftover last-dropout remaining at stop. Come back from leftover last-dropout remaining at the top of ending." + "Bass Guitar comes back at ending after sitting out at stop. Come in from the top of ending." ); }); - it("asks the player to confirm leftover last-dropout remaining return when every part stays active", () => { + it("asks the player to confirm the next return when no return is mapped", () => { setNavigatorLanguage("en-US"); const song = createDemoRehearsalSong(); render(); expect(screen.getByTestId("first-leftover-last-dropout-remaining-return")).toHaveTextContent( - "Tonight's first leftover last-dropout remaining return still needs a named leftover last-dropout remaining and a later remaining return. Confirm who comes back after leftover last-dropout remaining before the first section." + "The next return is not clear yet. Confirm which part comes back after parts drop out before rehearsal." ); }); @@ -522,4 +522,4 @@ describe("Workspace", () => { expect(screen.getByText("합주 우선순위")).toBeTruthy(); expect(screen.getByText("역할과 화성")).toBeTruthy(); }); -}); +}); \ No newline at end of file