-
Notifications
You must be signed in to change notification settings - Fork 0
feat(workspace): name the next instrument check on Ranges and Player #1052
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
20
commits into
develop
Choose a base branch
from
feat/ranges-player-next-instrument-check
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
20 commits
Select commit
Hold shift + click to select a range
d04fe65
feat(workspace): name the next instrument check on Ranges and Player
seonghobae 8505e45
fix(ranges): harden multi-section instrument checks
seonghobae b410842
test(ranges): keep id-less role callout aligned
seonghobae a61de25
test(ranges): reject id-less playable cards
seonghobae 397b7e4
fix(ranges): reject roles without stable ids
seonghobae 655f797
test(workspace): require buyer-visible Ranges and Player surfaces
seonghobae a64e95b
fix(workspace): expose Ranges and Player surfaces
seonghobae 93afdea
fix(ranges): guard nullable runtime song roots
seonghobae ba3fb1f
fix(workspace): share the canonical range callout
seonghobae 644c3a0
fix(ranges): centralize runtime object validation
seonghobae 8ecc90b
test(ranges): keep card selectors unique
seonghobae 0aa2078
fix(ranges): preserve the first playable span
seonghobae 1f9a4ef
test(ranges): describe first-span warning behavior
seonghobae 2554d90
docs(test): explain player locale fixture helper
seonghobae 24f8ed4
docs(test): explain ranges locale fixture helper
seonghobae bb17f42
test(player): reject Proxy get section substitution
seonghobae fe467cd
fix(player): snapshot owned section loop authority
seonghobae b737906
fix(ranges): trust only owned analysis evidence
seonghobae b88ccd1
fix(workspace): reject forged range and loop payloads
seonghobae f2dcc58
perf(workspace): memoize runtime song validation
seonghobae 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import { render, screen } from "@testing-library/react"; | ||
| import { createDemoRehearsalSong } from "@bandscope/shared-types"; | ||
| import { afterEach, describe, expect, it } from "vitest"; | ||
| import { PlayerFeature, firstNamedSection } from "./index"; | ||
|
|
||
| const originalLanguage = navigator.language; | ||
|
|
||
| /** Set the browser language used by locale detection for one test case. */ | ||
| function setNavigatorLanguage(language: string) { | ||
| Object.defineProperty(navigator, "language", { | ||
| configurable: true, | ||
| value: language | ||
| }); | ||
| } | ||
|
|
||
| describe("firstNamedSection", () => { | ||
| it("returns the first labeled window with a forward time range", () => { | ||
| expect(firstNamedSection(createDemoRehearsalSong())).toEqual({ id: "verse-1", label: "verse" }); | ||
| }); | ||
|
|
||
| it("skips blank labels and inverted windows", () => { | ||
| const song = createDemoRehearsalSong(); | ||
| const verse = song.sections[0]!; | ||
| song.sections = [ | ||
| { | ||
| ...verse, | ||
| id: " ", | ||
| label: "none", | ||
| timeRange: { start: 30, end: 10 } | ||
| }, | ||
| { | ||
| ...verse, | ||
| id: "chorus-1", | ||
| label: "chorus", | ||
| timeRange: { start: 30, end: 50 } | ||
| } | ||
| ]; | ||
| expect(firstNamedSection(song)).toEqual({ id: "chorus-1", label: "chorus" }); | ||
| }); | ||
|
|
||
| it("rejects Proxy section data instead of trusting descriptor reads", () => { | ||
| const song = createDemoRehearsalSong(); | ||
| const verse = song.sections[0]!; | ||
| song.sections = [ | ||
| new Proxy(verse, { | ||
| get(target, property, receiver) { | ||
| if (property === "id") return "spoofed-section"; | ||
| if (property === "label") return "chorus"; | ||
| if (property === "timeRange") return { start: 90, end: 100 }; | ||
| return Reflect.get(target, property, receiver); | ||
| } | ||
| }) | ||
| ]; | ||
|
|
||
| expect(firstNamedSection(song)).toBeNull(); | ||
| }); | ||
|
|
||
| it("rejects Proxy descriptor traps before they can forge a loop", () => { | ||
| const song = createDemoRehearsalSong(); | ||
| const forged = new Proxy(song, { | ||
| getOwnPropertyDescriptor(target, property) { | ||
| if (property === "sections") { | ||
| return { | ||
| configurable: true, | ||
| enumerable: true, | ||
| value: [{ id: "spoofed", label: "spoofed", timeRange: { start: 1, end: 2 } }], | ||
| writable: true | ||
| }; | ||
| } | ||
| return Reflect.getOwnPropertyDescriptor(target, property); | ||
| } | ||
| }); | ||
|
|
||
| expect(firstNamedSection(forged as RehearsalSong)).toBeNull(); | ||
| }); | ||
|
|
||
| it("rejects malformed roots instead of inventing a loop", () => { | ||
| expect(firstNamedSection(null)).toBeNull(); | ||
| expect(firstNamedSection({ sections: "bad" } as never)).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("PlayerFeature", () => { | ||
| afterEach(() => { | ||
| setNavigatorLanguage(originalLanguage); | ||
| }); | ||
|
|
||
| it("names the rehearsal map when no song is loaded", () => { | ||
| setNavigatorLanguage("en-US"); | ||
| render(<PlayerFeature title="Player" />); | ||
| expect( | ||
| screen.getByText( | ||
| "Open the rehearsal map and choose a song first. This window does not play audio yet." | ||
| ) | ||
| ).toBeTruthy(); | ||
| }); | ||
|
|
||
| it("names tonight's first map section without claiming playback", () => { | ||
| setNavigatorLanguage("en-US"); | ||
| render(<PlayerFeature title="Player" song={createDemoRehearsalSong()} />); | ||
|
|
||
| const callout = screen.getByTestId("player-next-map-loop"); | ||
| expect(callout).toHaveTextContent("Tonight's first loop"); | ||
| expect(callout).toHaveTextContent( | ||
| "Tonight's first section is verse. Open that section on the rehearsal map to set tonight's loop." | ||
| ); | ||
| expect(callout).toHaveTextContent("This window does not play audio yet."); | ||
| expect(screen.getByTestId("player-song-title")).toHaveTextContent("Late Night Set"); | ||
| }); | ||
|
|
||
| it("asks for a named window when no section can be looped", () => { | ||
| setNavigatorLanguage("en-US"); | ||
| const song = createDemoRehearsalSong(); | ||
| song.sections = []; | ||
| render(<PlayerFeature title="Player" song={song} />); | ||
| expect( | ||
| screen.getByText("Tonight's first section still needs a named window on the rehearsal map.") | ||
| ).toBeTruthy(); | ||
| }); | ||
| }); |
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 |
|---|---|---|
| @@ -1,56 +1,100 @@ | ||
| import { useMemo } from "react"; | ||
| import type { RehearsalSong } from "@bandscope/shared-types"; | ||
| import { createTranslator, detectPreferredLocale } from "../../i18n"; | ||
| import { | ||
| fillRangeCopy, | ||
| isSafeRuntimeValue, | ||
| meaningfulRangeText, | ||
| ownDataProperty | ||
| } from "../workspace/firstRangeSqueeze"; | ||
|
|
||
| /** Documented. */ | ||
| /** Tonight's first named section a player should loop from the rehearsal map. */ | ||
| export type FirstNamedSection = { | ||
| id: string; | ||
| label: string; | ||
| }; | ||
|
|
||
| /** Return whether an untrusted runtime value is a non-array object record. */ | ||
| function isRuntimeObject(value: unknown): value is Record<string, unknown> { | ||
| return typeof value === "object" && value !== null && !Array.isArray(value); | ||
| } | ||
|
|
||
| /** Pick the first named section window without treating malformed evidence as a loop. */ | ||
| export function firstNamedSection(song: RehearsalSong | null | undefined): FirstNamedSection | null { | ||
| const runtimeSong: unknown = song; | ||
| if (!isRuntimeObject(runtimeSong) || !isSafeRuntimeValue(runtimeSong)) { | ||
| return null; | ||
| } | ||
| const sections = ownDataProperty(runtimeSong, "sections"); | ||
| if (!Array.isArray(sections)) { | ||
| return null; | ||
| } | ||
| for (const sectionValue of sections) { | ||
| if (!isRuntimeObject(sectionValue)) { | ||
| continue; | ||
| } | ||
| const id = meaningfulRangeText(ownDataProperty(sectionValue, "id")); | ||
| const label = meaningfulRangeText(ownDataProperty(sectionValue, "label")); | ||
| if (!id || !label) { | ||
| continue; | ||
| } | ||
| const timeRange = ownDataProperty(sectionValue, "timeRange"); | ||
| if (!isRuntimeObject(timeRange)) { | ||
| continue; | ||
| } | ||
| const start = ownDataProperty(timeRange, "start"); | ||
| const end = ownDataProperty(timeRange, "end"); | ||
| if (typeof start !== "number" || typeof end !== "number" || !Number.isFinite(start) || !Number.isFinite(end) || end <= start) { | ||
| continue; | ||
| } | ||
| return { id, label }; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /** Name the next map loop when this window cannot play local audio yet. */ | ||
| export function PlayerFeature(props: { title: string; song?: RehearsalSong | null }) { | ||
|
seonghobae marked this conversation as resolved.
|
||
| const { title, song } = props; | ||
| const t = useMemo(() => createTranslator(detectPreferredLocale()), []); | ||
|
seonghobae marked this conversation as resolved.
|
||
| const safeSong = useMemo( | ||
| () => (song && isSafeRuntimeValue(song) ? song : null), | ||
| [song], | ||
| ); | ||
|
seonghobae marked this conversation as resolved.
|
||
| const namedSection = useMemo(() => firstNamedSection(safeSong), [safeSong]); | ||
| const songTitle = meaningfulRangeText( | ||
| isRuntimeObject(safeSong) ? ownDataProperty(safeSong, "title") : undefined | ||
| ); | ||
|
|
||
| if (!song) { | ||
| return ( | ||
| <section style={{ padding: "24px" }}> | ||
| <h2>{title}</h2> | ||
| <p style={{ color: "#999" }}>No song loaded. Start an analysis to use the player.</p> | ||
| <section className="space-y-4 rounded-3xl border border-cyan-300/20 bg-slate-950/72 p-5 text-slate-100 shadow-[0_20px_80px_rgba(0,0,0,0.24)]"> | ||
| <h2 className="text-2xl font-black tracking-tight text-white">{title}</h2> | ||
| <p className="text-sm leading-6 text-slate-300">{t("playerEmptyState")}</p> | ||
| </section> | ||
| ); | ||
| } | ||
|
|
||
| const nextAction = namedSection | ||
| ? fillRangeCopy(t("playerMapLoopNextAction"), { sectionLabel: namedSection.label }) | ||
| : t("playerMissingSection"); | ||
|
|
||
| return ( | ||
| <section style={{ padding: "24px" }}> | ||
| <h2>{title}</h2> | ||
| <div | ||
| style={{ | ||
| padding: "16px", | ||
| backgroundColor: "#fafafa", | ||
| borderRadius: "8px", | ||
| border: "1px solid #e8e8e8", | ||
| }} | ||
| <section className="space-y-4 text-slate-100"> | ||
| <h2 className="text-2xl font-black tracking-tight text-white">{title}</h2> | ||
| <section | ||
| className="rounded-2xl border border-amber-300/20 bg-amber-300/[0.07] p-4" | ||
| data-testid="player-next-map-loop" | ||
| aria-label={t("playerNextMapLoopTitle")} | ||
| > | ||
| <div style={{ marginBottom: "12px" }}> | ||
| <strong>{song.title}</strong> | ||
| <span style={{ color: "#666", marginLeft: "8px" }}> | ||
| {song.sections.length} {song.sections.length === 1 ? "section" : "sections"} | ||
| </span> | ||
| </div> | ||
| <div style={{ display: "flex", gap: "8px", flexWrap: "wrap" }}> | ||
| {song.sections.map((section) => ( | ||
| <span | ||
| key={section.id} | ||
| style={{ | ||
| padding: "4px 12px", | ||
| borderRadius: "16px", | ||
| backgroundColor: "#fff", | ||
| border: "1px solid #d9d9d9", | ||
| fontSize: "0.85em", | ||
| textTransform: "capitalize", | ||
| }} | ||
| > | ||
| {section.label} | ||
| </span> | ||
| ))} | ||
| </div> | ||
| <div style={{ marginTop: "16px", color: "#999", fontSize: "0.85em" }}> | ||
| Audio playback requires the desktop app with a local audio source. | ||
| </div> | ||
| </div> | ||
| <p className="text-xs font-black uppercase tracking-[0.24em] text-amber-200">{t("playerNextMapLoopTitle")}</p> | ||
| <p className="mt-2 text-sm leading-6 text-slate-100">{nextAction}</p> | ||
| <p className="mt-2 text-sm leading-6 text-slate-300">{t("playerNoAudioYet")}</p> | ||
| </section> | ||
| {namedSection && songTitle ? ( | ||
| <p className="text-sm font-semibold text-slate-200" data-testid="player-song-title"> | ||
| {songTitle} | ||
| </p> | ||
| ) : null} | ||
| </section> | ||
| ); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.