-
Notifications
You must be signed in to change notification settings - Fork 35
fix(player): record actual server-loaded arrangement instead of defaulting to 0 #1036
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
ColeChiodo
wants to merge
2
commits into
got-feedBack:main
Choose a base branch
from
ColeChiodo:fix/stats-record-correct-arrangement
base: main
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| 'use strict'; | ||
|
|
||
| const { test } = require('node:test'); | ||
| const assert = require('node:assert/strict'); | ||
|
|
||
| function makeFeedBack() { | ||
| const handlers = new Map(); | ||
| return { | ||
| on(event, fn) { | ||
| const list = handlers.get(event) || []; | ||
| list.push(fn); | ||
| handlers.set(event, list); | ||
| }, | ||
| emit(event, detail) { | ||
| (handlers.get(event) || []).forEach((fn) => fn({ detail })); | ||
| }, | ||
| capabilities: { snapshotDiagnostics: () => ({}) }, | ||
| }; | ||
| } | ||
|
|
||
| function setup() { | ||
| const posts = []; | ||
| const origFetch = global.fetch; | ||
| global.fetch = async (url, opts) => { | ||
| if (url === '/api/stats') { | ||
| posts.push(JSON.parse(opts.body)); | ||
| } | ||
| return { ok: true, json: async () => ({}) }; | ||
| }; | ||
| const fb = makeFeedBack(); | ||
| global.window = { feedBack: fb }; | ||
| require('../../static/v3/stats-recorder.js'); | ||
| return { posts, fb, cleanup: () => { global.fetch = origFetch; delete global.window; } }; | ||
| } | ||
|
|
||
| test('stats-recorder corrects arrangement from song:loaded', () => { | ||
| const { posts, fb, cleanup } = setup(); | ||
|
|
||
| // Scenario 1: instrument routing picks a different arrangement (e.g. bass) | ||
| fb.emit('song:loading', { filename: 'song.archive', arrangement: null }); | ||
| fb.emit('song:loaded', { | ||
| filename: 'song.archive', arrangement: 'Bass', | ||
| arrangementIndex: 2, | ||
| arrangements: [{ name: 'Lead' }, { name: 'Rhythm' }, { name: 'Bass' }], | ||
| }); | ||
| fb.emit('song:pause', { time: 30 }); | ||
| assert.equal(posts.length, 1, 'scenario 1: should have posted stats'); | ||
| assert.equal(posts[0].arrangement, 2, 'scenario 1: arrangement should be the server-chosen index (2)'); | ||
|
|
||
| // Scenario 2: arrangementIndex 0 is kept (guitar lead is correct) | ||
| fb.emit('song:loading', { filename: 'song2.archive', arrangement: null }); | ||
| fb.emit('song:loaded', { | ||
| filename: 'song2.archive', arrangement: 'Lead', | ||
| arrangementIndex: 0, | ||
| }); | ||
| fb.emit('song:pause', { time: 10 }); | ||
| assert.equal(posts.length, 2, 'scenario 2: should have posted stats'); | ||
| assert.equal(posts[1].arrangement, 0, 'scenario 2: should keep arrangement 0 when server selected it'); | ||
|
|
||
| // Scenario 3: explicit arrangement is preserved | ||
| fb.emit('song:loading', { filename: 'song3.archive', arrangement: 0 }); | ||
| fb.emit('song:loaded', { | ||
| filename: 'song3.archive', arrangement: 'Lead', | ||
| arrangementIndex: 0, | ||
| }); | ||
| fb.emit('song:pause', { time: 10 }); | ||
| assert.equal(posts.length, 3, 'scenario 3: should have posted stats'); | ||
| assert.equal(posts[2].arrangement, 0, 'scenario 3: explicit arrangement 0 preserved'); | ||
|
|
||
| cleanup(); | ||
| }); |
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.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: got-feedBack/feedBack
Length of output: 50377
🏁 Script executed:
Repository: got-feedBack/feedBack
Length of output: 23517
🏁 Script executed:
Repository: got-feedBack/feedBack
Length of output: 50377
Correlate
song:loadedwith the current session.song:loadedis emitted from the WebSocketsong_infopath and includesfilename, whilesong:loadingresetscur.filename. If an in-flight connection’ssong_infoarrives after a newplaySongorcloseCurrentSong, this handler can overwrite the active session’s arrangement and cause the next stats post to be attributed to the wrong song/arrangement pair. Required.filename === cur.filenameor gate updates against the same load/load-session identity before updatingcur.arrangement.🤖 Prompt for AI Agents