-
Notifications
You must be signed in to change notification settings - Fork 0
Test spa branch #92
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
jsoules
wants to merge
2
commits into
main
Choose a base branch
from
test-spa-branch
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
Test spa branch #92
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ export const updateSpaOutputForRun = async (runId: string) => { | |
| const resp = await postStanPlaygroundRequest(req) | ||
| if (resp.type !== 'getProjectFile') { | ||
| console.warn(resp) | ||
| throw Error('Unexpected response from Stan Playground') | ||
| throw Error('Unexpected response from Stan Playground while retrieving project file') | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made the error messages more specific to make it easier to distinguish the different test cases. |
||
| } | ||
| const sha1 = resp.projectFile.contentSha1 | ||
|
|
||
|
|
@@ -51,7 +51,7 @@ export const updateSpaOutputForRun = async (runId: string) => { | |
| const resp2 = await postStanPlaygroundRequest(req2) | ||
| if (resp2.type !== 'getDataBlob') { | ||
| console.warn(resp2) | ||
| throw Error('Unexpected response from Stan Playground') | ||
| throw Error('Unexpected response from Stan Playground while retrieving dataset') | ||
| } | ||
| const x = JSON.parse(resp2.content) | ||
| const spaOutput = x as SpaOutput | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -67,6 +67,14 @@ describe("Chain selection component", () => { | |
| expect(colorSets.length).toEqual(chains.length) | ||
| colorSets.forEach(cs => expect(chainColorsBase.includes(rgbToHex(cs))).toBeTruthy()) | ||
| }) | ||
| test("Renders black color swatch if appropriate color not found", () => { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd missed this case earlier. |
||
| render(<ChainsSelector chains={chains} allChainIds={allChainIds} chainColors={{}} />) | ||
| const squareSpans = screen.getAllByText(SOLID_SQUARE, {exact: false}) | ||
| expect(squareSpans.length).toEqual(chains.length) | ||
| const colorSets = squareSpans.map(s => s.style.color) | ||
| expect(colorSets.length).toEqual(chains.length) | ||
| colorSets.forEach(cs => expect(cs).toEqual('black')) | ||
| }) | ||
| test("Sets checkbox state to match selected chain ID state", async () => { | ||
| const localImport = (await import('../../src/components/ChainsSelector')) | ||
| const sut = localImport.default | ||
|
|
||
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,83 @@ | ||
| import { Mock, afterEach, beforeEach, describe, expect, test, vi } from 'vitest' | ||
|
|
||
| describe("Stan-playground chain fetching function", () => { | ||
| const selectedRunId = 'spa|prog1|file1' | ||
| const nonSelectedRunId = 'spa|prog1|file2' | ||
| const emptyRunId = 'spa|prog2|file1' | ||
| const nonexistentRunId = 'not-valid' | ||
| const mockSpaOutputsForRunIds = {} | ||
| const goodChains = [ | ||
| { | ||
| chainId: 'chain1', | ||
| rawHeader: 'header', | ||
| rawFooter: 'footer', | ||
| numWarmupDraws: 10, | ||
| sequences: { | ||
| a: [1, 2, 3], | ||
| b: [2, 3, 4] | ||
| } | ||
| }, { | ||
| chainId: 'chain2', | ||
| rawHeader: 'header', | ||
| rawFooter: 'footer', | ||
| sequences: { | ||
| a: [6, 7, 8], | ||
| b: [8, 9, 10] | ||
| } | ||
| } | ||
| ] | ||
| const notUsedChain = [{ chainId: 'chain3', rawHeader: '', rawFooter: '', sequences: {c: [4, 3, 2]} }] | ||
| mockSpaOutputsForRunIds[selectedRunId] = { | ||
| sha1: 'abc', | ||
| spaOutput: { chains: goodChains } | ||
| } | ||
| mockSpaOutputsForRunIds[nonSelectedRunId] = { | ||
| sha1: 'def', | ||
| spaOutput: { chains: notUsedChain } | ||
| } | ||
| mockSpaOutputsForRunIds[emptyRunId] = { | ||
| sha1: 'bar', | ||
| spaOutput: { chains: [] } | ||
| } | ||
| let mockUpdateSpaOutputForRun: Mock | ||
|
|
||
| beforeEach(() => { | ||
| mockUpdateSpaOutputForRun = vi.fn() | ||
|
|
||
| vi.doMock('../../src/spaInterface/spaOutputsForRunIds', () => { | ||
| return { | ||
| __esModule: true, | ||
| spaOutputsForRunIds: mockSpaOutputsForRunIds, | ||
| updateSpaOutputForRun: mockUpdateSpaOutputForRun | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| vi.resetAllMocks() | ||
| vi.resetModules() | ||
| }) | ||
|
|
||
| test("Updates the requested run id", async () => { | ||
| const sut = (await import("../../src/spaInterface/getSpaChainsForRun")).default | ||
| await sut(emptyRunId) | ||
| expect(mockUpdateSpaOutputForRun).toHaveBeenCalledOnce() | ||
| }) | ||
| test("Returns empty on cache miss", async () => { | ||
| // TODO: Verify console warning? | ||
| const sut = (await import('../../src/spaInterface/getSpaChainsForRun')).default | ||
| const result = await sut(nonexistentRunId) | ||
| expect(result.length).toBe(0) | ||
| }) | ||
| test("Returns an MCMCChain for each chain in the fetched stan-playground output", async () => { | ||
| const sut = (await import('../../src/spaInterface/getSpaChainsForRun')).default | ||
| const result = await sut(selectedRunId) | ||
| expect(result.length).toBe(goodChains.length) | ||
| const keys = result.map(r => r.chainId) | ||
| expect(keys.includes('chain1')).toBeTruthy() | ||
| expect(keys.includes('chain2')).toBeTruthy() | ||
| expect(keys.includes('chain3')).toBeFalsy() | ||
| expect(result[0].excludedInitialIterationCount).toBe(10) | ||
| expect(result[1].excludedInitialIterationCount).toBe(0) | ||
| }) | ||
| }) |
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,89 @@ | ||
| import { Mock, afterEach, beforeEach, describe, expect, test, vi } from 'vitest' | ||
| import { MCMCSequence } from '../../service/src/types' | ||
|
|
||
| describe("Stan-playground sequence update fetching function", () => { | ||
| const selectedRunId = 'spa|prog1|file1' | ||
| const nonSelectedRunId = 'spa|prog1|file2' | ||
| const emptyRunId = 'spa|prog2|file1' | ||
| const nonexistentRunId = 'not-valid' | ||
| const mockSpaOutputsForRunIds = {} | ||
| const goodChains = [ | ||
| { | ||
| chainId: 'chain1', | ||
| rawHeader: 'header', | ||
| rawFooter: 'footer', | ||
| numWarmupDraws: 10, | ||
| sequences: { | ||
| a: [1, 2, 3], | ||
| b: [2, 3, 4] | ||
| } | ||
| }, { | ||
| chainId: 'chain2', | ||
| rawHeader: 'header', | ||
| rawFooter: 'footer', | ||
| sequences: { | ||
| a: [6, 7, 8], | ||
| b: [8, 9, 10] | ||
| } | ||
| } | ||
| ] | ||
| const notUsedChain = [{ chainId: 'chain3', rawHeader: '', rawFooter: '', sequences: {c: [4, 3, 2]} }] | ||
| mockSpaOutputsForRunIds[selectedRunId] = { | ||
| sha1: 'abc', | ||
| spaOutput: { chains: goodChains } | ||
| } | ||
| mockSpaOutputsForRunIds[nonSelectedRunId] = { | ||
| sha1: 'def', | ||
| spaOutput: { chains: notUsedChain } | ||
| } | ||
| mockSpaOutputsForRunIds[emptyRunId] = { | ||
| sha1: 'bar', | ||
| spaOutput: { chains: [] } | ||
| } | ||
| let mockUpdateSpaOutputForRun: Mock | ||
|
|
||
| beforeEach(() => { | ||
| mockUpdateSpaOutputForRun = vi.fn() | ||
|
|
||
| vi.doMock('../../src/spaInterface/spaOutputsForRunIds', () => { | ||
| return { | ||
| __esModule: true, | ||
| spaOutputsForRunIds: mockSpaOutputsForRunIds, | ||
| updateSpaOutputForRun: mockUpdateSpaOutputForRun | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| vi.resetAllMocks() | ||
| vi.resetModules() | ||
| }) | ||
|
|
||
| test("Updates the requested run id", async () => { | ||
| const sut = (await import('../../src/spaInterface/getSpaSequenceUpdates')).default | ||
| await sut(emptyRunId, []) | ||
| expect(mockUpdateSpaOutputForRun).toHaveBeenCalledOnce() | ||
| }) | ||
| test("Returns empty list on cache miss", async () => { | ||
| // TODO: Verify console warning? | ||
| const sut = (await import('../../src/spaInterface/getSpaSequenceUpdates')).default | ||
| const result = await sut(nonexistentRunId, []) | ||
| expect(result).toBeDefined() | ||
| expect((result || []).length).toBe(0) | ||
| }) | ||
| test("Returns an MCMCSequenceUpdate for each returned sequence", async () => { | ||
| const searchedSequences = [ | ||
| {chainId: 'chain1', variableName: 'a', data: [1, 2]}, | ||
| {chainId: 'chain2', variableName: 'b', data: [8, 9]}, | ||
| {chainId: 'chain1', variableName: 'x', data: [1]} // should return nothing since variable name doesn't match | ||
| ] as unknown as MCMCSequence[] | ||
| const hits = searchedSequences.map(s => goodChains.find(c => c.chainId === s.chainId)?.sequences[s.variableName] ?? []) | ||
| expect(hits.length).toBe(searchedSequences.length) | ||
|
|
||
| const sut = (await import('../../src/spaInterface/getSpaSequenceUpdates')).default | ||
| const result = await sut(selectedRunId, searchedSequences) | ||
| expect(result).toBeDefined() | ||
| expect((result || []).length).toEqual(hits.length) | ||
| // TODO: Consider interrogating this more--or let integration tests pick it up? | ||
| }) | ||
| }) |
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,43 @@ | ||
| import { Mock, afterEach, beforeEach, describe, expect, test, vi } from 'vitest' | ||
|
|
||
| describe("Stan-playground data interaction function", () => { | ||
| const myUrl = 'https://mock.url' | ||
| const mockResponse = JSON.stringify({ id: 1, value: 'result' }) | ||
| let mockFetch: Mock | ||
| let originalFetch | ||
|
|
||
| beforeEach(() => { | ||
| originalFetch = global.fetch | ||
| mockFetch = vi.fn().mockResolvedValue({ json: () => mockResponse }) | ||
| global.fetch = mockFetch | ||
|
|
||
| vi.doMock('../../src/config', () => { | ||
| return { | ||
| __esModule: true, | ||
| stanPlaygroundUrl: myUrl | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| vi.resetAllMocks() | ||
| vi.resetModules() | ||
| global.fetch = originalFetch | ||
| }) | ||
|
|
||
| test("Fetches from configured URL", async () => { | ||
| const sut = (await import('../../src/spaInterface/postStanPlaygroundRequest')).default | ||
| const req = { data: 'original' } | ||
| const result = await sut(req) | ||
|
|
||
| expect(mockFetch).toHaveBeenCalledOnce() | ||
| expect(result).toEqual(mockResponse) | ||
|
|
||
| const call = mockFetch.mock.lastCall | ||
| const calledUrl = call[0] | ||
| const calledObj = call[1] | ||
| expect(calledUrl).toEqual(myUrl) | ||
| expect(calledObj.method).toEqual('POST') | ||
| expect(calledObj.body).toEqual(JSON.stringify({payload: req})) | ||
| }) | ||
| }) |
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.
Turns out that an empty list
([])is truthy.