Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/docs-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: docs-check

on:
pull_request:
paths:
- "docs/**"
- "README.md"
- "AGENTS.md"
- ".github/workflows/docs-check.yml"
push:
branches:
- main
paths:
- "docs/**"
- "README.md"
- "AGENTS.md"
- ".github/workflows/docs-check.yml"

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Check docs conventions
run: npx -y @simpledoc/simpledoc check
28 changes: 28 additions & 0 deletions .github/workflows/e2e-unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: e2e-unit-tests

on:
pull_request:
paths:
- "e2e/**"
- ".github/workflows/e2e-unit-tests.yml"
push:
branches:
- main
paths:
- "e2e/**"
- ".github/workflows/e2e-unit-tests.yml"

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Run e2e unit tests
run: node --test e2e/*.test.mjs
46 changes: 46 additions & 0 deletions .github/workflows/go-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: go-tests

on:
pull_request:
paths:
- "api/**"
- "operator/**"
- "integrations/github-app/**"
- ".github/workflows/go-tests.yml"
push:
branches:
- main
paths:
- "api/**"
- "operator/**"
- "integrations/github-app/**"
- ".github/workflows/go-tests.yml"

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: api
working-directory: api
- name: operator
working-directory: operator
- name: integrations-github-app
working-directory: integrations/github-app
defaults:
run:
working-directory: ${{ matrix.working-directory }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: ${{ matrix.working-directory }}/go.mod
cache-dependency-path: ${{ matrix.working-directory }}/go.sum

- name: Test
run: go test ./...
31 changes: 31 additions & 0 deletions .github/workflows/ui-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: ui-tests

on:
pull_request:
paths:
- "ui/**"
- ".github/workflows/ui-tests.yml"
push:
branches:
- main
paths:
- "ui/**"
- ".github/workflows/ui-tests.yml"

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Run UI tests
run: node --test ui/entrypoint.test.mjs ui/nginx-config.test.mjs ui/public/*.test.mjs

- name: Check entrypoint shell syntax
run: bash -n ui/entrypoint.sh
2 changes: 1 addition & 1 deletion e2e/acp-client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export async function connectACPWebSocket(url, timeoutSeconds, options = {}) {
}
pending.delete(id);
reject(new Error(`ACP request ${method} timed out`));
}, rpcTimeoutMs).unref?.();
}, rpcTimeoutMs);
});
}

Expand Down
9 changes: 7 additions & 2 deletions e2e/acp-smoke-lib.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,13 @@ export function resolveACPEndpoint(spritz) {
/**
* Load a Node-compatible WebSocket client constructor from the CLI dependency set.
*/
export function resolveWebSocketConstructor() {
const wsModule = cliRequire('ws');
export function resolveWebSocketConstructor(options = {}) {
const globalObject = options.globalObject ?? globalThis;
if (typeof globalObject?.WebSocket === 'function') {
return globalObject.WebSocket;
}
const requireFn = options.requireFn ?? cliRequire;
const wsModule = requireFn('ws');
return wsModule.WebSocket || wsModule.default || wsModule;
}

Expand Down
9 changes: 8 additions & 1 deletion e2e/acp-smoke-lib.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,15 @@ test('resolveACPEndpoint prefers discovered ACP port/path and normalizes the pat
});

test('resolveWebSocketConstructor returns a usable client constructor', () => {
const WebSocketCtor = resolveWebSocketConstructor();
class FakeWebSocket {}
const WebSocketCtor = resolveWebSocketConstructor({
globalObject: {},
requireFn() {
return { WebSocket: FakeWebSocket };
},
});
assert.equal(typeof WebSocketCtor, 'function');
assert.equal(WebSocketCtor, FakeWebSocket);
});

test('assertSmokeCreateResponse accepts canonicalized preset ids from the API', () => {
Expand Down
27 changes: 21 additions & 6 deletions operator/controllers/spritz_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,59 @@ import (
spritzv1 "spritz.sh/operator/api/v1"
)

func TestSpritzURLIngressAddsTrailingSlash(t *testing.T) {
func TestWorkspaceURLIngressAddsTrailingSlash(t *testing.T) {
spritz := &spritzv1.Spritz{}
spritz.Spec.Ingress = &spritzv1.SpritzIngress{
Host: "console.example.com",
Path: "/workspaces/w/tidy-fjord",
}

got := spritzURL(spritz)
got := spritzv1.WorkspaceURLForSpritz(spritz)
want := "https://console.example.com/workspaces/w/tidy-fjord/"
if got != want {
t.Fatalf("expected %q, got %q", want, got)
}
}

func TestSpritzURLIngressRootStaysRoot(t *testing.T) {
func TestWorkspaceURLIngressRootStaysRoot(t *testing.T) {
spritz := &spritzv1.Spritz{}
spritz.Spec.Ingress = &spritzv1.SpritzIngress{
Host: "console.example.com",
Path: "/",
}

got := spritzURL(spritz)
got := spritzv1.WorkspaceURLForSpritz(spritz)
want := "https://console.example.com/"
if got != want {
t.Fatalf("expected %q, got %q", want, got)
}
}

func TestSpritzURLIngressKeepsExistingTrailingSlash(t *testing.T) {
func TestWorkspaceURLIngressKeepsExistingTrailingSlash(t *testing.T) {
spritz := &spritzv1.Spritz{}
spritz.Spec.Ingress = &spritzv1.SpritzIngress{
Host: "console.example.com",
Path: "/workspaces/w/tidy-fjord/",
}

got := spritzURL(spritz)
got := spritzv1.WorkspaceURLForSpritz(spritz)
want := "https://console.example.com/workspaces/w/tidy-fjord/"
if got != want {
t.Fatalf("expected %q, got %q", want, got)
}
}

func TestSpritzURLPrefersChatURLWhenWorkspaceIsWebAccessible(t *testing.T) {
spritz := &spritzv1.Spritz{}
spritz.Name = "tidy-fjord"
spritz.Spec.Ingress = &spritzv1.SpritzIngress{
Host: "console.example.com",
Path: "/workspaces/w/tidy-fjord",
}

got := spritzURL(spritz)
want := "https://console.example.com/#chat/tidy-fjord"
if got != want {
t.Fatalf("expected %q, got %q", want, got)
}
}
7 changes: 4 additions & 3 deletions ui/entrypoint.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import vm from 'node:vm';
import { uiPath, uiPublicPath } from './test-paths.mjs';
import { execFileSync } from 'node:child_process';

function renderConfig(env = {}) {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'spritz-ui-'));
fs.copyFileSync('/Users/onur/repos/spritz/ui/public/config.js', path.join(tmpDir, 'config.js'));
fs.copyFileSync('/Users/onur/repos/spritz/ui/public/index.html', path.join(tmpDir, 'index.html'));
fs.copyFileSync(uiPublicPath('config.js'), path.join(tmpDir, 'config.js'));
fs.copyFileSync(uiPublicPath('index.html'), path.join(tmpDir, 'index.html'));

execFileSync('/bin/sh', ['/Users/onur/repos/spritz/ui/entrypoint.sh'], {
execFileSync('/bin/sh', [uiPath('entrypoint.sh')], {
env: {
...process.env,
SPRITZ_UI_HTML_DIR: tmpDir,
Expand Down
3 changes: 2 additions & 1 deletion ui/nginx-config.test.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { uiPath } from './test-paths.mjs';

const nginxConfig = fs.readFileSync('/Users/onur/repos/spritz/ui/nginx.conf', 'utf8');
const nginxConfig = fs.readFileSync(uiPath('nginx.conf'), 'utf8');

test('nginx config disables caching for index and runtime config', () => {
assert.match(nginxConfig, /location = \/index\.html \{[\s\S]*Cache-Control "no-store, max-age=0"/);
Expand Down
3 changes: 2 additions & 1 deletion ui/public/acp-client.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import vm from 'node:vm';
import { uiPublicPath } from '../test-paths.mjs';

function loadACPClientModule() {
const sockets = [];
Expand Down Expand Up @@ -57,7 +58,7 @@ function loadACPClientModule() {
});
context.globalThis = context.window;

vm.runInContext(fs.readFileSync('/Users/onur/repos/spritz/ui/public/acp-client.js', 'utf8'), context, {
vm.runInContext(fs.readFileSync(uiPublicPath('acp-client.js'), 'utf8'), context, {
filename: 'acp-client.js',
});

Expand Down
3 changes: 2 additions & 1 deletion ui/public/acp-layout-css.test.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { uiPublicPath } from '../test-paths.mjs';

const styles = fs.readFileSync('/Users/onur/repos/spritz/ui/public/styles.css', 'utf8');
const styles = fs.readFileSync(uiPublicPath('styles.css'), 'utf8');

function getRule(selector) {
const escapedSelector = selector.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
Expand Down
5 changes: 3 additions & 2 deletions ui/public/acp-page-cache.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import vm from 'node:vm';
import { uiPublicPath } from '../test-paths.mjs';

function createStorage(seed = {}) {
const values = new Map(Object.entries(seed));
Expand Down Expand Up @@ -110,10 +111,10 @@ function loadModules(storageSeed = {}, createACPClient = null) {
window.window = window;
const context = vm.createContext({ window, document, console, setTimeout, clearTimeout, URL, URLSearchParams });
context.globalThis = context.window;
vm.runInContext(fs.readFileSync('/Users/onur/repos/spritz/ui/public/acp-render.js', 'utf8'), context, {
vm.runInContext(fs.readFileSync(uiPublicPath('acp-render.js'), 'utf8'), context, {
filename: 'acp-render.js',
});
vm.runInContext(fs.readFileSync('/Users/onur/repos/spritz/ui/public/acp-page.js', 'utf8'), context, {
vm.runInContext(fs.readFileSync(uiPublicPath('acp-page.js'), 'utf8'), context, {
filename: 'acp-page.js',
});
return window;
Expand Down
5 changes: 3 additions & 2 deletions ui/public/acp-page-layout.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import vm from 'node:vm';
import { uiPublicPath } from '../test-paths.mjs';

function createElement(tagName) {
return {
Expand Down Expand Up @@ -75,9 +76,9 @@ function loadModules() {
window.window = window;
const context = vm.createContext({ window, document, console, setTimeout, clearTimeout });
context.globalThis = context.window;
const renderScript = fs.readFileSync('/Users/onur/repos/spritz/ui/public/acp-render.js', 'utf8');
const renderScript = fs.readFileSync(uiPublicPath('acp-render.js'), 'utf8');
vm.runInContext(renderScript, context, { filename: 'acp-render.js' });
const pageScript = fs.readFileSync('/Users/onur/repos/spritz/ui/public/acp-page.js', 'utf8');
const pageScript = fs.readFileSync(uiPublicPath('acp-page.js'), 'utf8');
vm.runInContext(pageScript, context, { filename: 'acp-page.js' });
return { window, document };
}
Expand Down
5 changes: 3 additions & 2 deletions ui/public/acp-page-notice.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import vm from 'node:vm';
import { uiPublicPath } from '../test-paths.mjs';

function createElement(tagName) {
return {
Expand Down Expand Up @@ -64,10 +65,10 @@ function loadModules(createACPClient) {
window.window = window;
const context = vm.createContext({ window, document, console, setTimeout, clearTimeout, URL, URLSearchParams });
context.globalThis = context.window;
vm.runInContext(fs.readFileSync('/Users/onur/repos/spritz/ui/public/acp-render.js', 'utf8'), context, {
vm.runInContext(fs.readFileSync(uiPublicPath('acp-render.js'), 'utf8'), context, {
filename: 'acp-render.js',
});
vm.runInContext(fs.readFileSync('/Users/onur/repos/spritz/ui/public/acp-page.js', 'utf8'), context, {
vm.runInContext(fs.readFileSync(uiPublicPath('acp-page.js'), 'utf8'), context, {
filename: 'acp-page.js',
});
return window;
Expand Down
5 changes: 3 additions & 2 deletions ui/public/acp-page-session-binding.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import vm from 'node:vm';
import { uiPublicPath } from '../test-paths.mjs';

function createElement(tagName) {
const listeners = new Map();
Expand Down Expand Up @@ -81,10 +82,10 @@ function loadModules(createACPClient) {
window.window = window;
const context = vm.createContext({ window, document, console, setTimeout, clearTimeout, URL, URLSearchParams });
context.globalThis = context.window;
vm.runInContext(fs.readFileSync('/Users/onur/repos/spritz/ui/public/acp-render.js', 'utf8'), context, {
vm.runInContext(fs.readFileSync(uiPublicPath('acp-render.js'), 'utf8'), context, {
filename: 'acp-render.js',
});
vm.runInContext(fs.readFileSync('/Users/onur/repos/spritz/ui/public/acp-page.js', 'utf8'), context, {
vm.runInContext(fs.readFileSync(uiPublicPath('acp-page.js'), 'utf8'), context, {
filename: 'acp-page.js',
});
return window;
Expand Down
Loading
Loading