-
Notifications
You must be signed in to change notification settings - Fork 0
feat(workspace): name tonight's first count-out on the map #1095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
seonghobae
wants to merge
2
commits into
develop
Choose a base branch
from
feat/workspace-first-count-out
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
apps/desktop/src/features/workspace/firstCountOut.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import { | ||
| createDemoRehearsalSong, | ||
| parseRehearsalSong, | ||
| type RehearsalSong | ||
| } from "@bandscope/shared-types"; | ||
| import { describe, expect, it } from "vitest"; | ||
| import { fillRangeCopy } from "./firstRangeSqueeze"; | ||
| import { firstCountOut, formatCountOutTime } from "./firstCountOut"; | ||
|
|
||
| function withSectionTime( | ||
| song: RehearsalSong, | ||
| timeRange: RehearsalSong["sections"][number]["timeRange"], | ||
| label: string = song.sections[0]!.label | ||
| ): RehearsalSong { | ||
| return { | ||
| ...song, | ||
| sections: song.sections.map((section, index) => | ||
| index === 0 | ||
| ? { ...section, label: label as RehearsalSong["sections"][number]["label"], timeRange } | ||
| : section | ||
| ) | ||
| }; | ||
| } | ||
|
|
||
| describe("formatCountOutTime", () => { | ||
| it("formats bounded whole seconds as m:ss", () => { | ||
| expect(formatCountOutTime(0)).toBe("0:00"); | ||
| expect(formatCountOutTime(30)).toBe("0:30"); | ||
| expect(formatCountOutTime(30.9)).toBe("0:30"); | ||
| expect(formatCountOutTime(90)).toBe("1:30"); | ||
| }); | ||
|
|
||
| it("fails closed on non-finite, negative, non-number, or oversized ends", () => { | ||
| for (const value of [Number.NaN, Number.POSITIVE_INFINITY, -1, "30", 4_294_967_296]) { | ||
| expect(formatCountOutTime(value)).toBeNull(); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe("firstCountOut", () => { | ||
| it("names the first section end from existing time-range evidence", () => { | ||
| expect(firstCountOut(createDemoRehearsalSong())).toEqual({ | ||
| sectionLabel: "verse", | ||
| endTime: "0:30" | ||
| }); | ||
| }); | ||
|
|
||
| it("does not turn migrated legacy timing placeholders into count-out evidence", () => { | ||
| const seed = createDemoRehearsalSong(); | ||
| const legacySong = { | ||
| ...seed, | ||
| sections: seed.sections.map(({ timeRange: _timeRange, ...section }) => section) | ||
|
Check failure on line 52 in apps/desktop/src/features/workspace/firstCountOut.test.ts
|
||
| }; | ||
| const migrated = parseRehearsalSong(legacySong); | ||
|
|
||
| expect(migrated.sections[0]!.timeRange).toEqual({ start: 0, end: 1 }); | ||
| expect(firstCountOut(migrated)).toBeNull(); | ||
| }); | ||
|
|
||
| it("skips blank labels until a named section end exists", () => { | ||
| const song = withSectionTime(createDemoRehearsalSong(), { start: 10, end: 30 }, "none"); | ||
| expect(firstCountOut(song)).toBeNull(); | ||
| }); | ||
|
|
||
| it("skips inverted, inherited, or malformed time ranges", () => { | ||
| const inherited = Object.create({ start: 10, end: 30 }) as RehearsalSong["sections"][number]["timeRange"]; | ||
| expect(firstCountOut(withSectionTime(createDemoRehearsalSong(), { start: 30, end: 10 }))).toBeNull(); | ||
| expect(firstCountOut(withSectionTime(createDemoRehearsalSong(), inherited))).toBeNull(); | ||
| expect( | ||
| firstCountOut(withSectionTime(createDemoRehearsalSong(), { start: Number.NaN, end: 30 })) | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it("keeps the selected active part on tonight's first count-out", () => { | ||
| expect(firstCountOut(createDemoRehearsalSong(), "lead-vocal")).toEqual({ | ||
| sectionLabel: "verse", | ||
| endTime: "0:30" | ||
| }); | ||
| }); | ||
|
|
||
| it("returns null when the selected part sits out of the only named end", () => { | ||
| const song = createDemoRehearsalSong(); | ||
| song.sections[0] = { | ||
| ...song.sections[0]!, | ||
| partGraph: song.sections[0]!.partGraph.map((node) => | ||
| node.role_id === "keys-right" ? { ...node, is_active: false } : node | ||
| ) | ||
| }; | ||
|
|
||
| expect(firstCountOut(song, "keys-right")).toBeNull(); | ||
| expect(firstCountOut(song, "missing-role")).toBeNull(); | ||
| }); | ||
|
|
||
| it("fails closed on malformed runtime roots", () => { | ||
| for (const malformed of [null, {}, { sections: {} }, { sections: [null] }]) { | ||
| expect(firstCountOut(malformed as unknown as RehearsalSong)).toBeNull(); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe("count-out copy filling", () => { | ||
| it("keeps rehearsal values literal", () => { | ||
| expect( | ||
| fillRangeCopy("{sectionLabel} ends at {endTime}.", { | ||
| sectionLabel: "verse {endTime}", | ||
| endTime: "0:30" | ||
| }) | ||
| ).toBe("verse {endTime} ends at 0:30."); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| import type { RehearsalSong } from "@bandscope/shared-types"; | ||
| import { meaningfulRangeText } from "./firstRangeSqueeze"; | ||
|
|
||
| /** Tonight's first named section end the band should count out together. */ | ||
| export type FirstCountOut = { | ||
| sectionLabel: string; | ||
| endTime: string; | ||
| }; | ||
|
|
||
| const MAX_SECTION_TIME_SECONDS = 4_294_967_295; | ||
|
|
||
| /** Return whether an untrusted runtime value is a plain object record. */ | ||
| function isRuntimeObject(value: unknown): value is Record<string, unknown> { | ||
| return typeof value === "object" && value !== null && !Array.isArray(value); | ||
| } | ||
|
|
||
| /** | ||
| * Format a bounded section end as `m:ss`, or fail closed. | ||
| * | ||
| * Rejects non-numbers, non-finite values, negatives, and ends above the | ||
| * shared section-time ceiling so a malformed payload cannot become a | ||
| * rehearsal count-out. | ||
| */ | ||
| export function formatCountOutTime(totalSeconds: unknown): string | null { | ||
| if (typeof totalSeconds !== "number" || !Number.isFinite(totalSeconds) || totalSeconds < 0) { | ||
| return null; | ||
| } | ||
| if (totalSeconds > MAX_SECTION_TIME_SECONDS) { | ||
| return null; | ||
| } | ||
| const whole = Math.floor(totalSeconds); | ||
| const minutes = Math.floor(whole / 60); | ||
| const seconds = (whole % 60).toString().padStart(2, "0"); | ||
| return `${minutes}:${seconds}`; | ||
| } | ||
|
|
||
| /** Admit an own-property boolean `is_active` flag. Inherited evidence is isolated. */ | ||
| function isOwnActive(value: Record<string, unknown>): boolean { | ||
| return Object.prototype.hasOwnProperty.call(value, "is_active") && value.is_active === true; | ||
| } | ||
|
|
||
| /** | ||
| * Return whether the selected part is on this section's count-out. | ||
| * | ||
| * Prefers own-property `partGraph` activity so a rest is not sold as a | ||
| * leave-together cue. Falls back to a named role on the section when no | ||
| * graph node exists. | ||
| */ | ||
| function sectionIncludesActiveRole( | ||
| sectionValue: Record<string, unknown>, | ||
| activeRole: string | ||
| ): boolean { | ||
| if (Array.isArray(sectionValue.partGraph)) { | ||
| let sawSelectedNode = false; | ||
| for (const nodeValue of sectionValue.partGraph) { | ||
| if ( | ||
| !isRuntimeObject(nodeValue) || | ||
| !Object.prototype.hasOwnProperty.call(nodeValue, "role_id") | ||
| ) { | ||
| continue; | ||
| } | ||
| const roleId = meaningfulRangeText(nodeValue.role_id); | ||
| if (roleId !== activeRole) { | ||
| continue; | ||
| } | ||
| sawSelectedNode = true; | ||
| if (isOwnActive(nodeValue)) { | ||
| return true; | ||
| } | ||
| } | ||
| if (sawSelectedNode) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| if (!Array.isArray(sectionValue.roles)) { | ||
| return false; | ||
| } | ||
| for (const roleValue of sectionValue.roles) { | ||
| if (!isRuntimeObject(roleValue) || !Object.prototype.hasOwnProperty.call(roleValue, "id")) { | ||
| continue; | ||
| } | ||
| if (meaningfulRangeText(roleValue.id) === activeRole) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Pick the first named section end a player should count out before leaving. | ||
| * | ||
| * Uses existing `timeRange.end` authority already produced by analysis. | ||
| * Blank labels, inverted spans, inherited time fields, inactive selected | ||
| * parts, and malformed roots fail closed. When a role is selected, only a | ||
| * section that includes that part as active is named. | ||
| */ | ||
| export function firstCountOut( | ||
| song: RehearsalSong | unknown, | ||
| activeRole: string | null = null | ||
| ): FirstCountOut | null { | ||
| if (!isRuntimeObject(song) || !Array.isArray(song.sections)) { | ||
| return null; | ||
| } | ||
|
|
||
| for (const sectionValue of song.sections) { | ||
| if (!isRuntimeObject(sectionValue)) { | ||
| continue; | ||
| } | ||
| const sectionLabel = meaningfulRangeText(sectionValue.label); | ||
| if (!sectionLabel) { | ||
| continue; | ||
| } | ||
| if (activeRole && !sectionIncludesActiveRole(sectionValue, activeRole)) { | ||
| continue; | ||
| } | ||
| if ( | ||
| !isRuntimeObject(sectionValue.timeRange) || | ||
| !Object.prototype.hasOwnProperty.call(sectionValue.timeRange, "start") || | ||
| !Object.prototype.hasOwnProperty.call(sectionValue.timeRange, "end") | ||
| ) { | ||
| continue; | ||
| } | ||
| const start = sectionValue.timeRange.start; | ||
| const end = sectionValue.timeRange.end; | ||
| if (typeof start !== "number" || !Number.isFinite(start) || start < 0) { | ||
| continue; | ||
| } | ||
| const endTime = formatCountOutTime(end); | ||
| if (!endTime || typeof end !== "number" || end < start) { | ||
| continue; | ||
| } | ||
| return { sectionLabel, endTime }; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Legacy projects show invented count-outs
After
legacySectionTimeRangecreates a placeholder,firstCountOuttreats it as analyzed timing. The map reports a false 0:01 ending.Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.