diff --git a/packages/core/src/options.ts b/packages/core/src/options.ts index 7661267e..854fa3c5 100644 --- a/packages/core/src/options.ts +++ b/packages/core/src/options.ts @@ -24,7 +24,7 @@ export function makeSavedSessionOptions(opts: SavedSessionOptions): Required { expect(config.savedSessions).toEqual({ enabled: true, maxAge: 86400, - storagePrefix: 'thebe-binder-', + storagePrefix: 'thebe-binder', }); }); test('server settings', () => { diff --git a/packages/core/tests/options.spec.ts b/packages/core/tests/options.spec.ts index 0f9a9cee..5db391b8 100644 --- a/packages/core/tests/options.spec.ts +++ b/packages/core/tests/options.spec.ts @@ -38,7 +38,7 @@ describe('options', () => { expect(makeSavedSessionOptions({})).toEqual({ enabled: true, maxAge: 86400, - storagePrefix: 'thebe-binder-', + storagePrefix: 'thebe-binder', }); }); test('overrides', () => { diff --git a/packages/core/tests/url.spec.ts b/packages/core/tests/url.spec.ts index 1630396a..b48ee9d7 100644 --- a/packages/core/tests/url.spec.ts +++ b/packages/core/tests/url.spec.ts @@ -1,7 +1,7 @@ import { describe, test, expect } from 'vitest'; import { WELL_KNOWN_REPO_PROVIDERS, makeBinderUrls } from '../src/url'; import { makeBinderOptions } from '../src/options'; -import type { BinderOptions } from '../src/types'; +import { Config } from '../src/config'; const binderUrl = 'https://binder.curvenote.dev/'; @@ -10,119 +10,170 @@ describe('building binder urls', () => { test('git', () => { expect( makeBinderUrls( - makeBinderOptions({ binderUrl, repoProvider: 'git' }), + new Config({ + binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'git' }), + }), WELL_KNOWN_REPO_PROVIDERS, ), ).toEqual({ build: 'https://binder.curvenote.dev/build/git/executablebooks%2Fthebe-binder-base/HEAD', launch: 'https://binder.curvenote.dev/v2/git/executablebooks%2Fthebe-binder-base/HEAD', + storageKey: + 'thebe-binder-https://binder.curvenote.dev/build/git/executablebooks%2Fthebe-binder-base/HEAD', }); expect( makeBinderUrls( - makeBinderOptions({ binderUrl, repoProvider: 'git', ref: 'main' }), + new Config({ + binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'git', ref: 'main' }), + }), WELL_KNOWN_REPO_PROVIDERS, ), ).toEqual({ build: 'https://binder.curvenote.dev/build/git/executablebooks%2Fthebe-binder-base/main', launch: 'https://binder.curvenote.dev/v2/git/executablebooks%2Fthebe-binder-base/main', + storageKey: + 'thebe-binder-https://binder.curvenote.dev/build/git/executablebooks%2Fthebe-binder-base/main', }); }); test('gitlab', () => { expect( makeBinderUrls( - makeBinderOptions({ binderUrl, repoProvider: 'gitlab' }), + new Config({ + binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'gitlab' }), + }), WELL_KNOWN_REPO_PROVIDERS, ), ).toEqual({ build: 'https://binder.curvenote.dev/build/gl/executablebooks%2Fthebe-binder-base/HEAD', launch: 'https://binder.curvenote.dev/v2/gl/executablebooks%2Fthebe-binder-base/HEAD', + storageKey: + 'thebe-binder-https://binder.curvenote.dev/build/gl/executablebooks%2Fthebe-binder-base/HEAD', }); expect( makeBinderUrls( - makeBinderOptions({ binderUrl, repoProvider: 'gitlab', ref: 'main' }), + new Config({ + binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'gitlab', ref: 'main' }), + }), WELL_KNOWN_REPO_PROVIDERS, ), ).toEqual({ build: 'https://binder.curvenote.dev/build/gl/executablebooks%2Fthebe-binder-base/main', launch: 'https://binder.curvenote.dev/v2/gl/executablebooks%2Fthebe-binder-base/main', + storageKey: + 'thebe-binder-https://binder.curvenote.dev/build/gl/executablebooks%2Fthebe-binder-base/main', }); }); test('github', () => { expect( makeBinderUrls( - makeBinderOptions({ binderUrl, repoProvider: 'github' }), + new Config({ + binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'github' }), + }), WELL_KNOWN_REPO_PROVIDERS, ), ).toEqual({ build: 'https://binder.curvenote.dev/build/gh/executablebooks/thebe-binder-base/HEAD', launch: 'https://binder.curvenote.dev/v2/gh/executablebooks/thebe-binder-base/HEAD', + storageKey: + 'thebe-binder-https://binder.curvenote.dev/build/gh/executablebooks/thebe-binder-base/HEAD', }); expect( makeBinderUrls( - makeBinderOptions({ binderUrl, repoProvider: 'github', ref: 'main' }), + new Config({ + binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'github', ref: 'main' }), + }), WELL_KNOWN_REPO_PROVIDERS, ), ).toEqual({ build: 'https://binder.curvenote.dev/build/gh/executablebooks/thebe-binder-base/main', launch: 'https://binder.curvenote.dev/v2/gh/executablebooks/thebe-binder-base/main', + storageKey: + 'thebe-binder-https://binder.curvenote.dev/build/gh/executablebooks/thebe-binder-base/main', }); }); test('gist', () => { expect( makeBinderUrls( - makeBinderOptions({ binderUrl, repoProvider: 'gist' }), + new Config({ + binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'gist' }), + }), WELL_KNOWN_REPO_PROVIDERS, ), ).toEqual({ build: 'https://binder.curvenote.dev/build/gist/executablebooks/thebe-binder-base/HEAD', launch: 'https://binder.curvenote.dev/v2/gist/executablebooks/thebe-binder-base/HEAD', + storageKey: + 'thebe-binder-https://binder.curvenote.dev/build/gist/executablebooks/thebe-binder-base/HEAD', }); expect( makeBinderUrls( - makeBinderOptions({ binderUrl, repoProvider: 'gist', ref: 'main' }), + new Config({ + binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'gist', ref: 'main' }), + }), WELL_KNOWN_REPO_PROVIDERS, ), ).toEqual({ build: 'https://binder.curvenote.dev/build/gist/executablebooks/thebe-binder-base/main', launch: 'https://binder.curvenote.dev/v2/gist/executablebooks/thebe-binder-base/main', + storageKey: + 'thebe-binder-https://binder.curvenote.dev/build/gist/executablebooks/thebe-binder-base/main', }); }); }); test('unknown provider throws', () => { expect(() => makeBinderUrls( - makeBinderOptions({ binderUrl, repoProvider: 'unknown' }), + new Config({ + binderOptions: makeBinderOptions({ binderUrl, repoProvider: 'unknown' }), + }), WELL_KNOWN_REPO_PROVIDERS, ), ).toThrow(); }); describe('custom providers', () => { test('known custom provider - no ref', () => { - const opts = { binderUrl, repoProvider: 'custom', repo: 'sunshine' }; + const binderOptions = { binderUrl, repoProvider: 'custom', repo: 'sunshine' }; + const c = new Config({ binderOptions }); const spec = { name: 'custom', - makeUrls: ({ repo, ref }: BinderOptions) => ({ - build: `https://custom.host.com/build/custom/${repo}${ref ? `~~~${ref}` : ''}`, - launch: `https://custom.host.com/v2/custom/${repo}${ref ? `~~~${ref}` : ''}`, + makeUrls: (config: Config) => ({ + build: `https://custom.host.com/build/custom/${config.binder.repo}`, + launch: `https://custom.host.com/v2/custom/${config.binder.repo}`, + storageKey: `thebe-binder-https://custom.host.com/v2/custom/${config.binder.repo}`, }), }; - expect(makeBinderUrls(opts, [spec])).toEqual({ + expect(makeBinderUrls(c, [spec])).toEqual({ build: `https://custom.host.com/build/custom/sunshine`, launch: `https://custom.host.com/v2/custom/sunshine`, + storageKey: 'thebe-binder-https://custom.host.com/v2/custom/sunshine', }); }); test('known custom provider - with ref', () => { - const opts = { binderUrl, repoProvider: 'custom', repo: 'sunshine', ref: 'unicorns' }; + const binderOptions = { + binderUrl, + repoProvider: 'custom', + repo: 'sunshine', + ref: 'unicorns', + }; + const c = new Config({ binderOptions }); const spec = { name: 'custom', - makeUrls: ({ repo, ref }: BinderOptions) => ({ - build: `https://custom.host.com/build/custom/${repo}${ref ? `~~~${ref}` : ''}`, - launch: `https://custom.host.com/v2/custom/${repo}${ref ? `~~~${ref}` : ''}`, + makeUrls: (config: Config) => ({ + build: `https://custom.host.com/build/custom/${config.binder.repo}${ + config.binder.ref ? `~~~${config.binder.ref}` : '' + }`, + launch: `https://custom.host.com/v2/custom/${config.binder.repo}${ + config.binder.ref ? `~~~${config.binder.ref}` : '' + }`, + storageKey: `thebe-binder-https://custom.host.com/v2/custom/${config.binder.repo}${ + config.binder.ref ? `~~~${config.binder.ref}` : '' + }`, }), }; - expect(makeBinderUrls(opts, [spec])).toEqual({ + expect(makeBinderUrls(c, [spec])).toEqual({ build: `https://custom.host.com/build/custom/sunshine~~~unicorns`, launch: `https://custom.host.com/v2/custom/sunshine~~~unicorns`, + storageKey: 'thebe-binder-https://custom.host.com/v2/custom/sunshine~~~unicorns', }); }); });