diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 132b871..22a4e71 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,15 +22,15 @@ jobs: name: Swift on Linux runs-on: ubuntu-24.04 # Matches .swift-version. - container: swift:6.4.1-noble + container: swift:6.4.2-noble timeout-minutes: 60 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: .build - key: swift-linux-6.4.1-${{ hashFiles('Package.resolved') }} - restore-keys: swift-linux-6.4.1- + key: swift-linux-6.4.2-${{ hashFiles('Package.resolved') }} + restore-keys: swift-linux-6.4.2- # Ubuntu's own just is too old for the justfile's [group] attribute. - name: Install just env: @@ -54,15 +54,15 @@ jobs: # maintainer's machine, so no publish secret ever reaches GitHub. name: Wasm build, smoke and editor tests runs-on: ubuntu-24.04 - container: swift:6.4.1-noble + container: swift:6.4.2-noble timeout-minutes: 60 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: VGraphWasm/.build - key: wasm-6.4.1-${{ hashFiles('VGraphWasm/Package.resolved') }} - restore-keys: wasm-6.4.1- + key: wasm-6.4.2-${{ hashFiles('VGraphWasm/Package.resolved') }} + restore-keys: wasm-6.4.2- - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: 24 @@ -101,19 +101,19 @@ jobs: cd ../.. && just test-editor engine: - # The build plugin CI runs against a release tag. Checked here on every change, - # so that a tag is not the first time it meets a new toolchain. + # The optimized engine the plugins bundle. Checked here on every change, so a + # release is not the first time it meets a new toolchain or outgrows 5 MB. name: Release engine build runs-on: ubuntu-24.04 - container: swift:6.4.1-noble + container: swift:6.4.2-noble timeout-minutes: 60 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: VGraphWasm/.build - key: engine-6.4.1-${{ hashFiles('VGraphWasm/Package.resolved') }} - restore-keys: engine-6.4.1- + key: engine-6.4.2-${{ hashFiles('VGraphWasm/Package.resolved') }} + restore-keys: engine-6.4.2- - run: ./scripts/ci-engine.sh scripts: @@ -129,7 +129,7 @@ jobs: - name: Shell tests run: | failed=0 - for t in check-wasm-optimized justfile-hygiene doctor-kegs doctor-sdk codeowners licence audit-public export-public release-engine publish-plugins; do + for t in check-wasm-optimized justfile-hygiene doctor-kegs doctor-sdk codeowners licence audit-public export-public publish-plugins; do echo "::group::$t" ./scripts/$t.test.sh || failed=1 echo "::endgroup::" diff --git a/.swift-version b/.swift-version index 306894a..04757a5 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -6.4.1 \ No newline at end of file +6.4.2 \ No newline at end of file diff --git a/AGENTS.md b/AGENTS.md index f61d271..274f4d7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -73,7 +73,7 @@ functions. The WASM build compiles under Embedded Swift (`-enable-experimental-feature Embedded`, SDK -`swift-6.4.0-RELEASE_wasm-embedded`). The build fails loudly if incompatible +`swift-<.swift-version>-RELEASE_wasm-embedded`). The build fails loudly if incompatible code enters the WASM dependency graph (VGraph, VGLanguage, VGraphSVG, VGraphvizLib, App, EditorCore, MathUtils, VGraphWasm). In those targets: @@ -93,8 +93,9 @@ that; they are not a pattern to copy for new code. Unicode normalization tables are linked from `/usr/lib/swift/embedded/wasm32-unknown-none-wasm/libswiftUnicodeDataTables.a` -(see `VGraphWasm/Package.swift`). Without it, every `String == String`, -`hasPrefix` and `contains` leaves an undefined symbol. +Without it, every `String == String`, `hasPrefix` and `contains` leaves an +undefined symbol. When the build can't find the archive, read +`docs/wasm-unicode-tables.md` before searching the disk. `vgraph-cli`, `vgraph-mcp`, `vgraph-mcp-http` and `VGraphMCPTools` sit outside that graph and may use Foundation and key paths freely. diff --git a/Sources/VGraph/Domain/Attributes/Attribute.swift b/Sources/VGraph/Domain/Attributes/Attribute.swift index 4454f27..c6c05fd 100644 --- a/Sources/VGraph/Domain/Attributes/Attribute.swift +++ b/Sources/VGraph/Domain/Attributes/Attribute.swift @@ -114,6 +114,38 @@ extension Optional: AttributeType where Wrapped: AttributeType { } } +// An element may itself contain the separator (a wrapped line "Yes, soon", a +// point "1,2"), so `,` and `\` inside an element are backslash-escaped. +private func escapeElement(_ element: String) -> String { + var result = "" + for ch in element { + if ch == "\\" || ch == "," { result.append("\\") } + result.append(ch) + } + return result +} + +private func splitElements(_ body: String) -> [String] { + var elements: [String] = [] + var current = "" + var escaped = false + for ch in body { + if escaped { + current.append(ch) + escaped = false + } else if ch == "\\" { + escaped = true + } else if ch == "," { + elements.append(current) + current = "" + } else { + current.append(ch) + } + } + elements.append(current) + return elements.map { $0.trimmingCharacters(in: " \t\n\r") }.filter { !$0.isEmpty } +} + extension Array: AttributeType, VProtocol where Element: AttributeType { public static var typeName: String { @@ -127,13 +159,12 @@ extension Array: AttributeType, VProtocol where Element: AttributeType { } trimmed.removeFirst() trimmed.removeLast() - let elementsString = trimmed.split(separator: ",").map { $0.trimmingCharacters(in: " \t\n\r") } - let elements: [Element] = try elementsString.map(Element.fromString) + let elements: [Element] = try splitElements(trimmed).map(Element.fromString) return elements } public var asString: String { - return "[" + self.map { $0.asString }.joined(separator: ",") + "]" + return "[" + self.map { escapeElement($0.asString) }.joined(separator: ",") + "]" } } diff --git a/Sources/VGraphvizLib/Domain/DotExporter.swift b/Sources/VGraphvizLib/Domain/DotExporter.swift index 9139710..fb36c3b 100644 --- a/Sources/VGraphvizLib/Domain/DotExporter.swift +++ b/Sources/VGraphvizLib/Domain/DotExporter.swift @@ -251,23 +251,9 @@ public struct DotExporter: ForExportAGraph { return formatAttributeContainer(attributes, definitions: graph.attributeDefinitions) } - /// Converts array string format "[item1, item2]" to newline-separated format "item1\nitem2" + /// One DOT line per array element. private func formatArrayValue(_ value: String) -> String { - var trimmed = value.trimmed() - guard trimmed.hasPrefix("[") && trimmed.hasSuffix("]") else { - return value - } - - trimmed.removeFirst() - trimmed.removeLast() - - guard !trimmed.isEmpty else { - return "" - } - - let elements = trimmed.components(separatedBy: ",").map { - String($0).trimmed() - } + guard let elements = try? [String].fromString(value) else { return value } return elements.joined(separator: "\\n") } diff --git a/Tests/VGraphTests/AttributeTests.swift b/Tests/VGraphTests/AttributeTests.swift index c32ccdb..b544b6a 100644 --- a/Tests/VGraphTests/AttributeTests.swift +++ b/Tests/VGraphTests/AttributeTests.swift @@ -185,6 +185,21 @@ struct AttributeTests { #expect(retrieved4.count == 1) } + @Test("A wrapped line that contains a comma stays one line") + func arrayElementsKeepTheirCommas() throws(VError) { + let lines = ["Yes, soon", "a\\b", "x,", ",y", "\\,"] + let stored = try Attributes.Node.wrappedText.attribute(lines) + #expect(try Attributes.Node.wrappedText.value(fromString: stored.stringValue) == lines) + } + + @Test("A problem message that contains a comma stays one message") + func messagesKeepTheirCommas() throws(VError) { + let problems = TypedAttributeDefinition<[MessageWithSeverity]>( + id: "test.problems", name: "problems", description: "", defaultValue: [], target: .node) + let messages = [MessageWithSeverity(message: "missing, or empty", severity: .warning)] + #expect(try problems.value(fromString: problems.attribute(messages).stringValue) == messages) + } + @Test func vRectAttributeType() throws(VError) { let rectDef = TypedAttributeDefinition( diff --git a/VGraphWasm/README.md b/VGraphWasm/README.md index 835916c..b3a62ce 100644 --- a/VGraphWasm/README.md +++ b/VGraphWasm/README.md @@ -14,20 +14,13 @@ just wasm --release # optimized build with wasm-opt ``` `just wasm` wraps `build-wasm.sh`, which switches to the WASM SDK -(`swift-6.4.0-RELEASE_wasm-embedded`), builds this package for WASI, generates +(`swift-<.swift-version>-RELEASE_wasm-embedded`), builds this package for WASI, generates the JavaScript bindings with BridgeJS, and copies the output to `../website/Package/`. ## The Unicode tables -`libswiftUnicodeDataTables.a` must be linked or every `String` comparison fails -to link (see AGENTS.md). `build-wasm.sh` finds it and exports -`EMBEDDED_UNICODE_LIB_DIR`; `Package.swift` otherwise walks `$PATH` for an -`*.xctoolchain/usr/bin` entry. Where neither works, set the variable yourself: - -- **Linux swiftly** has no `.xctoolchain` in its layout - (`~/.swiftly/toolchains//usr/bin`), so the `$PATH` walk misses it. -- **Other toolchains may not ship the archive.** Both `Package.swift` and - `build-wasm.sh` fail with a clear error. Once the wasm SDK ships it, this - machinery can go. -- **Building for WASI from Xcode is untested.** +`libswiftUnicodeDataTables.a` must be linked, or every `String` comparison fails +to link. Where it lives, how the build finds it and what to do when it can't: +[docs/wasm-unicode-tables.md](../docs/wasm-unicode-tables.md). Building for +WASI from Xcode is untested. diff --git a/VGraphWasm/Tests-Browser/README.md b/VGraphWasm/Tests-Browser/README.md index fb92d3d..719640d 100644 --- a/VGraphWasm/Tests-Browser/README.md +++ b/VGraphWasm/Tests-Browser/README.md @@ -36,3 +36,20 @@ The decision logic that needs no DOM lives in Swift and is unit tested there — Playwright's own input is either a mouse — always `pointerType: "mouse"` — or a bare `touchscreen.tap()`, and neither can express a finger drag. - `website/index.html` pulls the WASI shim from a CDN, so a run needs network. + +## The Obsidian smoke + +`obsidian/` is a separate suite, run by `just obsidian-smoke`, not by `just +test`: it needs a desktop Obsidian and the cloned plugin, and it opens a window. +It loads the built `obsidian-vithanco/main.js` into a second Obsidian instance +with its own `--user-data-dir`, so the maintainer's open Obsidian is never +touched, and tests the newest `obsidian-.asar` from their install rather +than the older one the installer bundles. Set `OBSIDIAN_PLUGIN_DIR`, +`OBSIDIAN_BIN` or `OBSIDIAN_ASAR` (empty: the bundled version) to point it +elsewhere. + +- Playwright's `_electron.launch` cannot attach — Obsidian's builds disable the + Node inspector — so the app is spawned with `--remote-debugging-port` and + reached over CDP. +- `browser.close()` over CDP can hang. The instance is killed by matching its + `--user-data-dir`, never by app name. diff --git a/VGraphWasm/Tests-Browser/obsidian/playwright.config.js b/VGraphWasm/Tests-Browser/obsidian/playwright.config.js new file mode 100644 index 0000000..0da29fe --- /dev/null +++ b/VGraphWasm/Tests-Browser/obsidian/playwright.config.js @@ -0,0 +1,13 @@ +// Not part of `just test-editor`: it needs a desktop Obsidian install and the +// cloned plugin, and it opens a window. Run it with `just obsidian-smoke`. + +import { defineConfig } from '@playwright/test'; + +export default defineConfig({ + testDir: '.', + workers: 1, + reporter: 'list', + outputDir: '../test-results/obsidian', + timeout: 180_000, + expect: { timeout: 30_000 }, +}); diff --git a/VGraphWasm/Tests-Browser/obsidian/smoke.spec.js b/VGraphWasm/Tests-Browser/obsidian/smoke.spec.js new file mode 100644 index 0000000..11c795a --- /dev/null +++ b/VGraphWasm/Tests-Browser/obsidian/smoke.spec.js @@ -0,0 +1,205 @@ +// The plugin inside a real Obsidian: a throwaway vault in a second instance +// with its own --user-data-dir, so the maintainer's open Obsidian is untouched. +// +// Playwright's `_electron.launch` cannot drive Obsidian (its builds disable the +// Node inspector), so the app is spawned with a remote-debugging port and +// reached over CDP. + +import { test, expect, chromium } from '@playwright/test'; +import { spawn, execFileSync } from 'node:child_process'; +import fs from 'node:fs'; +import net from 'node:net'; +import os from 'node:os'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const here = path.dirname(fileURLToPath(import.meta.url)); +const pluginDir = path.resolve(process.env.OBSIDIAN_PLUGIN_DIR ?? path.join(here, '../../../obsidian-vithanco')); +const obsidianBin = process.env.OBSIDIAN_BIN ?? '/Applications/Obsidian.app/Contents/MacOS/Obsidian'; +const NOTE = 'Vithanco smoke.md'; + +// The installer's bundled app.asar lags the version users run; Obsidian loads +// the newest obsidian-.asar it finds in its user-data dir. +function newestInstalledAsar() { + if (process.env.OBSIDIAN_ASAR !== undefined) return process.env.OBSIDIAN_ASAR || null; + const dir = path.join(os.homedir(), 'Library/Application Support/obsidian'); + const version = (f) => f.slice('obsidian-'.length, -'.asar'.length).split('.').map(Number); + const newer = (a, b) => { for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] - b[i]; return 0; }; + const asars = fs.existsSync(dir) ? fs.readdirSync(dir).filter((f) => /^obsidian-\d+\.\d+\.\d+\.asar$/.test(f)) : []; + asars.sort((a, b) => newer(version(b), version(a))); + return asars.length ? path.join(dir, asars[0]) : null; +} + +function freePort() { + return new Promise((resolve, reject) => { + const srv = net.createServer().listen(0, '127.0.0.1', () => { + const { port } = srv.address(); + srv.close(() => resolve(port)); + }).on('error', reject); + }); +} + +function writeVault(workDir) { + const userData = path.join(workDir, 'userdata'); + const vault = path.join(workDir, 'vault'); + const installed = path.join(vault, '.obsidian/plugins/vithanco'); + fs.mkdirSync(userData, { recursive: true }); + fs.mkdirSync(installed, { recursive: true }); + for (const f of ['main.js', 'manifest.json', 'styles.css']) { + fs.copyFileSync(path.join(pluginDir, f), path.join(installed, f)); + } + const asar = newestInstalledAsar(); + if (asar) fs.copyFileSync(asar, path.join(userData, path.basename(asar))); + fs.writeFileSync(path.join(userData, 'obsidian.json'), JSON.stringify({ + vaults: { smoke000000000001: { path: vault, ts: Date.now(), open: true } }, + updateDisabled: true, + })); + fs.writeFileSync(path.join(vault, NOTE), [ + '```vgl', + 'vgraph decision: IBIS "Should we ship the plugin?" {', + ' node q1: Question "Should we ship?";', + ' node a1: Answer "Yes, soon";', + ' edge q1 -> a1;', + '}', + '```', + '', + '```vgl', + 'vgraph broken: IBIS "x" { node q1: Question "?"', + '```', + '', + ].join('\n')); + return userData; +} + +// Every Obsidian process (main and helpers) carries --user-data-dir, so this +// reaches exactly the test instance and never the maintainer's. +function killInstance(userData) { + try { execFileSync('pkill', ['-f', `user-data-dir=${userData}`]); } catch { /* none left */ } +} + +async function connect(port) { + for (let i = 0; i < 120; i++) { + try { return await chromium.connectOverCDP(`http://127.0.0.1:${port}`); } catch { await new Promise((r) => setTimeout(r, 500)); } + } + throw new Error('Obsidian did not open its debugging port'); +} + +async function obsidianWindow(browser) { + for (let i = 0; i < 120; i++) { + const page = browser.contexts().flatMap((c) => c.pages()).find((p) => p.url().startsWith('app://')); + if (page) return page; + await new Promise((r) => setTimeout(r, 500)); + } + throw new Error('No Obsidian window appeared'); +} + +test.describe.configure({ mode: 'serial' }); + +let workDir, userData, child, page; +const pageErrors = []; + +test.beforeAll(async () => { + workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'vithanco-obsidian-smoke-')); + userData = writeVault(workDir); + const port = await freePort(); + child = spawn(obsidianBin, [`--user-data-dir=${userData}`, `--remote-debugging-port=${port}`], { stdio: 'ignore' }); + const browser = await connect(port); + page = await obsidianWindow(browser); + page.on('pageerror', (e) => pageErrors.push(e.message)); + await page.waitForFunction(() => window.app?.workspace?.layoutReady, null, { timeout: 60_000 }); + + // A new vault that ships plugins asks before running them. + const trust = page.getByRole('button', { name: 'Trust author and enable plugins' }); + await trust.click({ timeout: 10_000 }).catch(() => {}); + await page.evaluate(async () => { + await app.plugins.setEnable(true); + await app.plugins.loadManifests(); + await app.plugins.enablePluginAndSave('vithanco'); + }); +}); + +// `browser.close()` over CDP can hang; killing the app drops the connection. +test.afterAll(async () => { + child?.kill('SIGTERM'); + if (userData) killInstance(userData); + if (workDir) fs.rmSync(workDir, { recursive: true, force: true }); +}); + +async function renderIn(theme) { + await page.evaluate(async ({ theme, note }) => { + app.changeTheme(theme); + const leaf = app.workspace.getLeaf(false); + await leaf.openFile(app.vault.getAbstractFileByPath(note), { state: { mode: 'preview' } }); + leaf.view.previewMode.rerender(true); + }, { theme, note: NOTE }); + const view = page.locator('.markdown-reading-view'); + const svg = view.locator('.vithanco-container svg').first(); + await expect(svg).toBeVisible(); + await expect(view.locator('.vithanco-error-block')).toBeVisible(); + return page.evaluate(() => { + const view = document.querySelector('.markdown-reading-view'); + const svg = view.querySelector('.vithanco-container svg'); + const box = svg.getBoundingClientRect(); + return { + dark: document.body.classList.contains('theme-dark'), + size: [box.width, box.height], + labels: [...svg.querySelectorAll('text')].map((t) => t.textContent), + fills: [...new Set([...svg.querySelectorAll('[fill]')].map((e) => e.getAttribute('fill')))].sort(), + error: view.querySelector('.vithanco-error-block').textContent, + }; + }); +} + +test('the plugin loads at the version in its manifest', async () => { + const manifest = JSON.parse(fs.readFileSync(path.join(pluginDir, 'manifest.json'), 'utf8')); + const loaded = await page.evaluate(() => app.plugins.plugins.vithanco?.manifest.version ?? null); + expect(loaded).toBe(manifest.version); + const obsidian = await page.evaluate(() => require('electron').ipcRenderer.sendSync('version')); + test.info().annotations.push({ type: 'obsidian', description: obsidian }); + console.log(`Obsidian ${obsidian}, plugin ${loaded}`); +}); + +let light; + +test('a vgl block renders an SVG in the light theme, and a broken one shows the error block', async () => { + light = await renderIn('moonstone'); + expect(light.dark).toBe(false); + expect(light.size[0]).toBeGreaterThan(0); + expect(light.size[1]).toBeGreaterThan(0); + expect(light.labels).toContain('Should we ship?'); + expect(light.labels.join(' ')).toContain('Yes,'); + expect(light.error).toMatch(/error/i); +}); + +test('the same blocks render in the dark theme, in dark colours', async () => { + const dark = await renderIn('obsidian'); + expect(dark.dark).toBe(true); + expect(dark.size[0]).toBeGreaterThan(0); + expect(dark.labels).toContain('Should we ship?'); + expect(dark.error).toMatch(/error/i); + expect(dark.fills).not.toEqual(light.fills); +}); + +// Obsidian 1.13+ indexes `settingItems` for its settings search and renders the +// tab from the same definitions; a tab that only implements display() has neither. +test('the settings tab is declared, so settings search can find it', async () => { + const tab = await page.evaluate(async () => { + app.setting.open(); + app.setting.openTabById('vithanco'); + await new Promise((r) => setTimeout(r, 300)); + const t = app.setting.pluginTabs.find((p) => p.id === 'vithanco'); + const names = (items) => items.flatMap((i) => [i.name, ...names(i.items ?? [])]).filter(Boolean); + const result = { + indexed: names(t?.settingItems ?? []), + rendered: [...t.containerEl.querySelectorAll('.setting-item-name')].map((e) => e.textContent), + }; + app.setting.close(); + return result; + }); + expect(tab.indexed).toEqual(expect.arrayContaining(['Syntax guide', 'Notations gallery', 'Sponsor on GitHub'])); + expect(tab.rendered).toEqual(expect.arrayContaining(['Syntax guide', 'Notations gallery', 'Sponsor on GitHub'])); +}); + +test('no uncaught errors in the window', async () => { + expect(pageErrors).toEqual([]); +}); diff --git a/build-wasm.sh b/build-wasm.sh index ab3f972..266be51 100755 --- a/build-wasm.sh +++ b/build-wasm.sh @@ -54,7 +54,9 @@ export PATH="$HOME/.swiftly/bin:$PATH" STEP_START=$SECONDS cd VGraphWasm -export TOOLCHAINS=$(swiftly use) +# The swiftly shim picks the toolchain from .swift-version, and refuses to run +# when TOOLCHAINS names anything else. +unset TOOLCHAINS # The Embedded WASM SDK, derived from .swift-version so it matches the toolchain. . "$SCRIPT_DIR/scripts/wasm-sdk.sh" # Enable BridgeJS experimental feature for @JS macro support. @@ -67,27 +69,7 @@ export JAVASCRIPTKIT_EXPERIMENTAL_EMBEDDED_WASM=true # cross-compile. Without it, it would pick the macOS xcframework and fail to link. export GRAPHVIZ_WASM=1 -# Resolve the xctoolchain's `libswiftUnicodeDataTables.a` directory and run an -# early sanity check, so a misconfigured toolchain fails here with a clear -# diagnostic instead of at link time with 50 undefined-symbol errors. -# -# VGraphWasm/Package.swift can resolve the same path itself (it shells out to -# `swift -print-target-info`) — this block just gives users the early signal, -# and exports the value for any tooling that wants to inspect it. -if [ -z "${EMBEDDED_UNICODE_LIB_DIR:-}" ]; then - SWIFT_RUNTIME_RESOURCE_PATH=$(swift -print-target-info | sed -n 's/.*"runtimeResourcePath": "\(.*\)".*/\1/p') - if [ -n "$SWIFT_RUNTIME_RESOURCE_PATH" ]; then - EMBEDDED_UNICODE_LIB_DIR="${SWIFT_RUNTIME_RESOURCE_PATH}/embedded/wasm32-unknown-none-wasm" - fi -fi -if [ -z "${EMBEDDED_UNICODE_LIB_DIR:-}" ] || [ ! -f "${EMBEDDED_UNICODE_LIB_DIR}/libswiftUnicodeDataTables.a" ]; then - echo "ERROR: libswiftUnicodeDataTables.a is required for the Embedded WASM link." >&2 - echo " Looked for it under '${EMBEDDED_UNICODE_LIB_DIR:-}'." >&2 - echo " Set EMBEDDED_UNICODE_LIB_DIR to the directory containing the archive," >&2 - echo " or ensure 'swift -print-target-info' returns a valid runtimeResourcePath." >&2 - exit 1 -fi -export EMBEDDED_UNICODE_LIB_DIR +. "$SCRIPT_DIR/scripts/embedded-unicode.sh" || exit 1 # wasm-strip and wasm-opt can be installed yet unlinked (see scripts/brew-kegs.sh). . "$SCRIPT_DIR/scripts/brew-kegs.sh" diff --git a/docs/adr/0001-editor-ui-in-wasm-via-elementaryui.md b/docs/adr/0001-editor-ui-in-wasm-via-elementaryui.md index 23c3b2c..2c5071e 100644 --- a/docs/adr/0001-editor-ui-in-wasm-via-elementaryui.md +++ b/docs/adr/0001-editor-ui-in-wasm-via-elementaryui.md @@ -115,5 +115,6 @@ maintenance liability to watch. - **Engine, website and both plugins are untouched**; existing engine tests remain the parity safety net. The editor gets thin JS smoke tests plus browser-preview verification. The plugins were build- and lint-validated but - not launched in-host — a runtime smoke inside Obsidian and VSCode is still owed - before a plugin release. + not launched in-host. `just obsidian-smoke` now runs the Obsidian plugin + in-host (light and dark theme, plus the error block); a runtime smoke inside + VSCode is still owed before a plugin release. diff --git a/docs/adr/0035-a-release-is-a-tag-started-from-the-maintainers-machine.md b/docs/adr/0035-a-release-is-a-tag-started-from-the-maintainers-machine.md index 57c6da2..7838cdf 100644 --- a/docs/adr/0035-a-release-is-a-tag-started-from-the-maintainers-machine.md +++ b/docs/adr/0035-a-release-is-a-tag-started-from-the-maintainers-machine.md @@ -4,7 +4,8 @@ Date: 2026-11-06 ## Status -Accepted. +Superseded by [0036](./0036-releases-stay-on-the-maintainers-machine.md) before +any release used it. ## Context diff --git a/docs/adr/0036-releases-stay-on-the-maintainers-machine.md b/docs/adr/0036-releases-stay-on-the-maintainers-machine.md new file mode 100644 index 0000000..33eeaad --- /dev/null +++ b/docs/adr/0036-releases-stay-on-the-maintainers-machine.md @@ -0,0 +1,33 @@ +# 36. Releases stay on the maintainer's machine + +Date: 2026-11-08 + +## Status + +Accepted. Supersedes [0035](./0035-a-release-is-a-tag-started-from-the-maintainers-machine.md). + +## Context + +0035 had a VGraph tag start each plugin's build on GitHub and open a bump PR there. +That left the release half on GitHub and half local, and finishing it on GitHub +would have needed either publish credentials in public repositories or OIDC +trust granted to them. Neither is wanted. + +## Decision + +A release is built, tagged and published from the maintainer's machine, with the +maintainer's own credentials: `just plugins-release`, `just release`, then +`just publish-all` or the `publish-*` recipes it runs. No repository holds a +publish or cross-repository credential. + +GitHub only checks. VGraph's CI builds the optimized engine on every change, and +each plugin's CI builds against VGraph's `main`, so an engine change that breaks a +plugin shows before a release rather than during one. + +## Consequences + +The version bump in VGraph (`plugins.json`, `vgraph-mcp-node`) reaches `main` +through a PR like any other change, because `main` takes no direct pushes. + +`publish-plugins` refuses a plugin checkout that is not on `main`: it tags and +pushes whatever is checked out. diff --git a/docs/wasm-unicode-tables.md b/docs/wasm-unicode-tables.md new file mode 100644 index 0000000..6c41606 --- /dev/null +++ b/docs/wasm-unicode-tables.md @@ -0,0 +1,62 @@ +# The Embedded Unicode tables + +Every `String ==`, `hasPrefix`, `contains` and `split` in the wasm module needs +Swift's Unicode normalization data. Embedded Swift doesn't link it by itself. +The build takes it from the **host toolchain**: + +``` +/usr/lib/swift/embedded/wasm32-unknown-none-wasm/libswiftUnicodeDataTables.a +``` + +The `swift--RELEASE_wasm` SDK bundles under +`~/Library/org.swift.swiftpm/swift-sdks/` carry a copy too, inside their own +`swift.xctoolchain`. The build doesn't use those copies, so seeing one there +doesn't mean the build can find the archive. + +With swiftly on macOS, `` is +`~/Library/Developer/Toolchains/swift-<.swift-version>-RELEASE.xctoolchain`. +`swiftly use --print-location` prints it. Without the archive, the link fails +with about 50 undefined `_swift_stdlib_getNormData`-style symbols. + +## How the build finds it + +`build-wasm.sh` sources `scripts/embedded-unicode.sh`, which exports +`EMBEDDED_UNICODE_LIB_DIR`: + +1. If `EMBEDDED_UNICODE_LIB_DIR` is already set, it is used. +2. Otherwise it takes `runtimeResourcePath` from `swift -print-target-info` and + appends `embedded/wasm32-unknown-none-wasm`. + +`VGraphWasm/Package.swift` reads that variable and adds the linker flags for +WASI only. If the flags also reached host builds, the macro plugins would try +to link a wasm archive with macOS `ld`. The manifest can't run `swift` itself +because SwiftPM sandboxes it, so when the variable is unset it falls back to +the first `*.xctoolchain/usr/bin` entry on `$PATH`. Under swiftly, `$PATH` holds +`~/.swiftly/bin` instead, so a direct `swift build` of `VGraphWasm` needs the +variable set by hand. Use `build-wasm.sh`. + +## When the lookup fails + +The error repeats what `swift` said, and that usually points at the cause. +Causes seen so far: + +- **`TOOLCHAINS` holds something swiftly doesn't recognise.** The swiftly shim + then refuses to run `swift` ("swiftly has picked another toolchain"). + swiftly 1.2's bare `swiftly use` prints a sentence, not a toolchain id, and + `build-wasm.sh` used to export that sentence as `TOOLCHAINS`. The build now + unsets the variable and lets `.swift-version` choose the toolchain. +- **`swift` is `/usr/bin/swift` (CommandLineTools)**, which has no Embedded + wasm32 libraries. Non-login shells skip `~/.zprofile`, so `build-wasm.sh` + puts `~/.swiftly/bin` first in `$PATH`. +- **The pinned toolchain isn't installed.** `swiftly install "$(cat .swift-version)"`. +- **Linux swiftly** keeps toolchains under `~/.swiftly/toolchains/`, with + no `.xctoolchain` in the path. `print-target-info` still works there; only the + manifest's `$PATH` fallback misses it. + +To check this machine by hand: + +```bash +ls "$(swiftly use --print-location)/usr/lib/swift/embedded/wasm32-unknown-none-wasm/libswiftUnicodeDataTables.a" +``` + +All of this can go once the `_wasm-embedded` SDK links the tables itself. diff --git a/justfile b/justfile index e29525c..3fde242 100644 --- a/justfile +++ b/justfile @@ -253,11 +253,11 @@ test filter='': build ./scripts/justfile-hygiene.test.sh ./scripts/doctor-kegs.test.sh ./scripts/doctor-sdk.test.sh + ./scripts/embedded-unicode.test.sh ./scripts/codeowners.test.sh ./scripts/licence.test.sh ./scripts/audit-public.test.sh ./scripts/export-public.test.sh - ./scripts/release-engine.test.sh ./scripts/publish-plugins.test.sh just _plugin-lint-if-present @@ -279,6 +279,30 @@ test-editor filter='': npx playwright install --with-deps chromium >/dev/null npx playwright test {{ if filter == "" { "" } else { "-g " + quote(filter) } }} +# The built obsidian-vithanco plugin inside a real Obsidian (separate instance, throwaway vault). +[group('test')] +obsidian-smoke: + #!/usr/bin/env bash + # Lint and build never load main.js into Obsidian; this does, in the light + # and dark theme. Opens a window. See VGraphWasm/Tests-Browser/README.md. + set -euo pipefail + BIN="${OBSIDIAN_BIN:-/Applications/Obsidian.app/Contents/MacOS/Obsidian}" + if [ ! -x "$BIN" ]; then + echo "· skipping obsidian-smoke: Obsidian is not installed ($BIN)"; exit 0 + fi + if [ ! -d obsidian-vithanco ]; then + echo "· skipping obsidian-smoke: obsidian-vithanco/ is not cloned (just plugins-setup)"; exit 0 + fi + if [ ! -f obsidian-vithanco/main.js ]; then + echo "obsidian-vithanco/main.js is missing — run 'just obsidian-build'." >&2; exit 1 + fi + # The spec kills its instance; this covers an interrupted run. The pattern + # names only the smoke's temp dirs, never the maintainer's Obsidian. + trap "pkill -f 'user-data-dir=.*/vithanco-obsidian-smoke-' || true" EXIT + cd VGraphWasm/Tests-Browser + [ -d node_modules ] || npm install --silent + npx playwright test -c obsidian/playwright.config.js + # Fail on any formatting deviation. `--strict` is load-bearing: without it the # linter prints its warnings and still exits 0, so nothing would ever go red. [group('test')] @@ -498,11 +522,6 @@ parity: (_require-plugin "obsidian-vithanco") (_require-plugin "vscode-vithanco" # Publish (outward-facing — the only irreversible recipes) # ═══════════════════════════════════════════════════════════════════════════ -# Tag VGraph vVERSION from a clean main, then have each plugin build against it and open a bump PR. -[group('publish')] -release-engine version: _require-maintainer - ./scripts/release-engine.sh {{quote(version)}} - # Commit + push + tag + GitHub release for BOTH plugins (parity-guarded). Stops before the marketplace. [group('publish')] publish-plugins: _require-maintainer (_require-plugin "obsidian-vithanco") (_require-plugin "vscode-vithanco") @@ -521,6 +540,11 @@ publish-plugins: _require-maintainer (_require-plugin "obsidian-vithanco") (_req FAIL=0 for spec in "obsidian-vithanco:main.js" "vscode-vithanco:vithanco-${OBS_V}.vsix"; do DIR=${spec%%:*}; ASSET=${spec#*:} + BRANCH=$(git -C "$DIR" branch --show-current) + if [ "$BRANCH" != main ]; then + echo "Preflight: $DIR is on '$BRANCH', not main — the release would tag and push that branch." >&2 + FAIL=1 + fi if git -C "$DIR" rev-parse -q --verify "refs/tags/$OBS_V" >/dev/null; then echo "Preflight: $DIR already has tag $OBS_V — bump before publishing." >&2 FAIL=1 @@ -557,7 +581,7 @@ publish-plugins: _require-maintainer (_require-plugin "obsidian-vithanco") (_req ( cd obsidian-vithanco # main.js is gitignored in this repo — it ships as a GitHub release asset (below), not a commit. git add manifest.json package.json versions.json styles.css VGraphWasm.wasm - # A merged bump PR may already have committed all of this. + # The bump may already be committed; then there is nothing to add. git diff --cached --quiet || git commit -m "chore: release $OBS_V" git tag "$OBS_V" git push origin HEAD "$OBS_V" diff --git a/plugins.json b/plugins.json index d7231a3..5e28ae5 100644 --- a/plugins.json +++ b/plugins.json @@ -3,17 +3,17 @@ "plugins": [ { "path": "obsidian-vithanco", - "version": "1.0.10", + "version": "1.0.11", "repo": "https://github.com/Vithanco/obsidian-vithanco.git" }, { "path": "vscode-vithanco", - "version": "1.0.10", + "version": "1.0.11", "repo": "https://github.com/Vithanco/vscode-vithanco.git" }, { "path": "vgraph-mcp-node", - "version": "1.0.10" + "version": "1.0.11" } ] } diff --git a/release-plugins.sh b/release-plugins.sh index cb145b0..a637d43 100755 --- a/release-plugins.sh +++ b/release-plugins.sh @@ -130,4 +130,6 @@ printf '%s' "$SUMMARY" | while IFS= read -r s; do echo " $s"; done echo "" echo "plugins.json updated. Nothing committed, tagged or pushed." echo "" -echo "Next: just publish-plugins # commits, tags and creates both GitHub releases" +echo "Next: just release # builds what publish-plugins ships" +echo " just publish-plugins # commits, tags and creates both GitHub releases" +echo " then commit plugins.json and vgraph-mcp-node here in a PR; main takes no direct pushes" diff --git a/scripts/ci-wasm-sdk.sh b/scripts/ci-wasm-sdk.sh index a04eebe..3295644 100755 --- a/scripts/ci-wasm-sdk.sh +++ b/scripts/ci-wasm-sdk.sh @@ -4,7 +4,7 @@ set -euo pipefail # swift.org's checksum for this release; it must change along with .swift-version. -CHECKSUM=783e6128d174d9f975b4eda68be02a5960681b723ef372e6876a7c2543a365d8 +CHECKSUM=83baca83553f8c443cda7b84800912e6e709c3acd2e7ebf277794ca5836c0da5 V=$(tr -d '[:space:]' < "$(dirname "$0")/../.swift-version") swift sdk install \ diff --git a/scripts/embedded-unicode.sh b/scripts/embedded-unicode.sh new file mode 100644 index 0000000..e504ac9 --- /dev/null +++ b/scripts/embedded-unicode.sh @@ -0,0 +1,35 @@ +# Sourced, not run. Exports EMBEDDED_UNICODE_LIB_DIR, the toolchain directory +# holding libswiftUnicodeDataTables.a, or explains why it could not. Failing +# here beats ~50 undefined _swift_stdlib_getNormData symbols at link time. +# Background: docs/wasm-unicode-tables.md. + +_embedded_unicode_fail() { + echo "ERROR: libswiftUnicodeDataTables.a is required for the Embedded WASM link." >&2 + printf ' %s\n' "$@" >&2 + echo " See docs/wasm-unicode-tables.md." >&2 + return 1 +} + +_embedded_unicode_resolve() { + if [ -z "${EMBEDDED_UNICODE_LIB_DIR:-}" ]; then + local info resource + # A stale TOOLCHAINS makes the swiftly shim refuse to run swift at all. + if ! info=$(env -u TOOLCHAINS swift -print-target-info 2>&1); then + _embedded_unicode_fail "\`swift -print-target-info\` failed with:" "$info" + return 1 + fi + resource=$(sed -n 's/.*"runtimeResourcePath": *"\([^"]*\)".*/\1/p' <<<"$info") + if [ -z "$resource" ]; then + _embedded_unicode_fail "\`swift -print-target-info\` reported no runtimeResourcePath." + return 1 + fi + EMBEDDED_UNICODE_LIB_DIR="$resource/embedded/wasm32-unknown-none-wasm" + fi + if [ ! -f "$EMBEDDED_UNICODE_LIB_DIR/libswiftUnicodeDataTables.a" ]; then + _embedded_unicode_fail "Not found in '$EMBEDDED_UNICODE_LIB_DIR'." + return 1 + fi + export EMBEDDED_UNICODE_LIB_DIR +} + +_embedded_unicode_resolve diff --git a/scripts/embedded-unicode.test.sh b/scripts/embedded-unicode.test.sh new file mode 100755 index 0000000..c658769 --- /dev/null +++ b/scripts/embedded-unicode.test.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +# The Embedded wasm link needs the toolchain's libswiftUnicodeDataTables.a. When +# the lookup fails, the error must say why — swift's own complaint and where it +# looked — because "" alone has sent us searching the disk more than once. +set -uo pipefail + +FAILED=0 +fail() { echo "FAIL: $*" >&2; FAILED=1; } +# check "" : passes when the command succeeds. +check() { local name=$1; shift; "$@" || fail "$name"; } + +REPO=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) +WORK=$(mktemp -d) +trap 'rm -rf "$WORK"' EXIT + +TOOLCHAIN="$WORK/tc/usr/lib/swift" +LIB="$TOOLCHAIN/embedded/wasm32-unknown-none-wasm" +mkdir -p "$LIB" "$WORK/bin" +touch "$LIB/libswiftUnicodeDataTables.a" + +# stub_swift : a `swift` whose -print-target-info runs . +stub_swift() { + printf '#!/bin/sh\n%s\n' "$1" > "$WORK/bin/swift" + chmod +x "$WORK/bin/swift" +} +# resolve [VAR=value...]: sources the helper and sets OUT, STATUS and DIR. +resolve() { + OUT=$(env -u EMBEDDED_UNICODE_LIB_DIR "$@" PATH="$WORK/bin:$PATH" bash -c \ + '. "$1" && echo "DIR=$EMBEDDED_UNICODE_LIB_DIR"' _ "$REPO/scripts/embedded-unicode.sh" 2>&1) + STATUS=$? + DIR=$(sed -n 's/^DIR=//p' <<<"$OUT") +} + +stub_swift "printf '{\"paths\": {\n \"runtimeResourcePath\": \"$TOOLCHAIN\"\n}}\n'" +resolve +check "1. Given swift reports a runtimeResourcePath holding the archive, when the helper is sourced, then EMBEDDED_UNICODE_LIB_DIR is its embedded wasm32 dir" \ + test "$STATUS" = 0 -a "$DIR" = "$LIB" + +stub_swift "[ -z \"\${TOOLCHAINS:-}\" ] || { echo 'TOOLCHAINS leaked' >&2; exit 1; } +printf '{\"runtimeResourcePath\": \"$TOOLCHAIN\"}\n'" +resolve TOOLCHAINS="Swift 6.4.1 (/repo/.swift-version)" +check "10. Given a stale TOOLCHAINS in the environment, when the helper is sourced, then swift runs without it and the lookup succeeds" \ + test "$STATUS" = 0 -a "$DIR" = "$LIB" + +stub_swift "exit 1" +resolve EMBEDDED_UNICODE_LIB_DIR="$LIB" +check "2. Given EMBEDDED_UNICODE_LIB_DIR is set, when the helper is sourced, then it is kept and swift is not asked" \ + test "$STATUS" = 0 -a "$DIR" = "$LIB" + +stub_swift "echo 'STUB: swiftly has picked another toolchain' >&2; exit 1" +resolve +check "3. Given swift fails, when the helper is sourced, then it fails" \ + test "$STATUS" != 0 +check "4. Given swift fails, when the helper is sourced, then the error repeats what swift said" \ + grep -q "STUB: swiftly has picked another toolchain" <<<"$OUT" + +stub_swift "printf '{\"runtimeResourcePath\": \"$WORK/elsewhere/usr/lib/swift\"}\n'" +resolve +check "5. Given the toolchain has no archive, when the helper is sourced, then it fails" \ + test "$STATUS" != 0 +check "6. Given the toolchain has no archive, when the helper is sourced, then the error names the directory it looked in" \ + grep -q "$WORK/elsewhere/usr/lib/swift/embedded/wasm32-unknown-none-wasm" <<<"$OUT" +check "7. Given any failure, when the helper is sourced, then the error points at the doc that explains the lookup" \ + grep -q "docs/wasm-unicode-tables.md" <<<"$OUT" + +check "8. Given build-wasm.sh, when read, then it sources scripts/embedded-unicode.sh" \ + grep -q "scripts/embedded-unicode.sh" "$REPO/build-wasm.sh" +# swiftly 1.2's bare `swiftly use` prints a sentence, not a toolchain id; put in +# TOOLCHAINS, it makes the swiftly shim refuse to run swift at all. +check "9. Given build-wasm.sh, when read, then it does not set TOOLCHAINS from \`swiftly use\`" \ + bash -c '! grep -q "TOOLCHAINS=.*swiftly use" "$1"' _ "$REPO/build-wasm.sh" + +exit $FAILED diff --git a/scripts/publish-plugins.test.sh b/scripts/publish-plugins.test.sh index 2b3843e..551eb92 100755 --- a/scripts/publish-plugins.test.sh +++ b/scripts/publish-plugins.test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# The bump can reach a plugin's main through a merged bump PR, leaving nothing to +# The bump can already be committed on a plugin's main, leaving nothing to # commit. `git commit` then exits non-zero and `set -e` stops the recipe, which # used to leave the Obsidian plugin published and the VS Code one not. set -uo pipefail @@ -50,7 +50,7 @@ given_plugins_at() { # version, in a fresh directory WORK with pushed plugin rep } publish() { just --justfile "$REPO_ROOT/justfile" --working-directory "$WORK" publish-plugins >"$WORK/out" 2>&1; } -# Given a bump PR already merged and nothing to commit, when publishing, then both plugins are tagged and released. +# Given the bump already committed and nothing to commit, when publishing, then both plugins are tagged and released. given_plugins_at 1.2.3 publish || fail "publishing with nothing to commit failed: $(cat "$WORK/out")" for p in obsidian-vithanco vscode-vithanco; do @@ -65,5 +65,16 @@ publish || fail "publishing a changed engine failed: $(cat "$WORK/out")" [ "$(git -C "$WORK/obsidian-vithanco" log -1 --format=%s 1.2.3)" = "chore: release 1.2.3" ] \ || fail "the changed engine was not committed under the tag" +# Given a plugin checked out on another branch, when publishing, then nothing is +# pushed, tagged or released: `git push origin HEAD` would release that branch. +given_plugins_at 1.2.3 +git -C "$WORK/vscode-vithanco" switch -qc some-pr +publish && fail "published from a branch other than main" +grep -q 'some-pr' "$WORK/out" || fail "does not name the branch: $(cat "$WORK/out")" +for p in obsidian-vithanco vscode-vithanco; do + git -C "$WORK/$p.git" rev-parse -q --verify refs/tags/1.2.3 >/dev/null && fail "$p was tagged" +done +grep -q '^release create' "$GH_LOG" && fail "created a release" + [ "$FAILED" -eq 0 ] && echo "✓ publish-plugins" exit "$FAILED" diff --git a/scripts/release-engine.sh b/scripts/release-engine.sh deleted file mode 100755 index 76eb2c0..0000000 --- a/scripts/release-engine.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash -# Tag a VGraph release and start each plugin's build against it. The maintainer's -# own gh login starts them, so no cross-repository token has to live in CI. -set -euo pipefail - -cd "$(dirname "$0")/.." - -VERSION=${1:-} -TAG="v$VERSION" -die() { echo "Error: $*" >&2; echo "Nothing was released." >&2; exit 1; } - -[[ "$VERSION" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]] || die "version must be plain semver such as 1.2.3, got '$VERSION'" -[ "$(git branch --show-current)" = main ] || die "release from main" -[ -z "$(git status --porcelain)" ] || die "the working tree is not clean" -git fetch -q origin main -[ "$(git rev-parse HEAD)" = "$(git rev-parse FETCH_HEAD)" ] || die "main differs from origin/main" -[ -z "$(git ls-remote --tags origin "refs/tags/$TAG")" ] || die "$TAG already exists on origin" - -REPOS=$(node -e " - for (const p of JSON.parse(require('fs').readFileSync('plugins.json', 'utf8')).plugins) { - if (p.repo) console.log(p.repo.replace('https://github.com/', '').replace(/\.git\$/, '')); - } -") -for repo in $REPOS; do - gh workflow view ci.yml --repo "$repo" >/dev/null || die "$repo has no ci.yml workflow to start" -done - -git tag "$TAG" -git push -q origin "refs/tags/$TAG" -echo "Pushed $TAG." - -status=0 -for repo in $REPOS; do - args=(ci.yml --repo "$repo" -f "vgraph_ref=$TAG" -f "release_version=$VERSION") - if gh workflow run "${args[@]}"; then - echo "Started the build of $repo." - else - echo "Error: the build of $repo did not start. $TAG stands; start it with:" >&2 - echo " gh workflow run ${args[*]}" >&2 - status=1 - fi -done -[ "$status" -eq 0 ] && echo "Each plugin opens a bump PR once it builds. After merging them: just plugins-pull, just release, just publish-plugins." -exit "$status" diff --git a/scripts/release-engine.test.sh b/scripts/release-engine.test.sh deleted file mode 100755 index 6599b5e..0000000 --- a/scripts/release-engine.test.sh +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env bash -# A VGraph release is a v* tag plus a build of each plugin against it. The tag -# cannot be taken back, so everything that can fail must fail before it is pushed. -set -uo pipefail - -SCRIPT=$(cd "$(dirname "$0")" && pwd)/release-engine.sh -ROOT=$(mktemp -d) -trap 'rm -rf "$ROOT"' EXIT -FAILED=0 -fail() { echo "FAIL: $*" >&2; FAILED=1; } - -mkdir "$ROOT/bin" -cat > "$ROOT/bin/gh" <<'EOF' -#!/usr/bin/env bash -echo "$*" >> "$GH_LOG" -case "$*" in - "workflow view"*) [ -z "${GH_VIEW_FAILS:-}" ] ;; - "workflow run"*) [ -z "${GH_RUN_FAILS:-}" ] ;; -esac -EOF -chmod +x "$ROOT/bin/gh" -export PATH="$ROOT/bin:$PATH" -export GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@example.invalid GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@example.invalid - -CASE=0 -given_a_clean_main() { # sets REPO, ORIGIN and GH_LOG - CASE=$((CASE + 1)) - ORIGIN="$ROOT/$CASE-origin.git" - REPO="$ROOT/$CASE-repo" - export GH_LOG="$ROOT/$CASE-gh.log" - : > "$GH_LOG" - git init -q --bare -b main "$ORIGIN" - git init -q -b main "$REPO" - mkdir "$REPO/scripts" - cp "$SCRIPT" "$REPO/scripts/" - cat > "$REPO/plugins.json" <<'EOF' -{"plugins":[ - {"path":"obsidian-vithanco","version":"1.0.0","repo":"https://github.com/Vithanco/obsidian-vithanco.git"}, - {"path":"vscode-vithanco","version":"1.0.0","repo":"https://github.com/Vithanco/vscode-vithanco.git"}, - {"path":"vgraph-mcp-node","version":"1.0.0"} -]} -EOF - git -C "$REPO" add . && git -C "$REPO" commit -qm init - git -C "$REPO" remote add origin "$ORIGIN" - git -C "$REPO" push -q origin main -} -run() { ( cd "$REPO" && ./scripts/release-engine.sh "$@" ) >"$ROOT/out" 2>&1; } -tag_pushed() { git -C "$ORIGIN" rev-parse -q --verify "refs/tags/$1" >/dev/null; } -refused() { # description, then: nothing reached origin and no plugin was started - grep -q 'workflow run' "$GH_LOG" && fail "$1: started a plugin build" - [ -z "$(git -C "$ORIGIN" tag)" ] || fail "$1: pushed a tag" -} - -# Given a clean main, when releasing, then the tag lands and each plugin with a repo builds against it. -given_a_clean_main -run 1.2.3 || fail "clean release failed: $(cat "$ROOT/out")" -tag_pushed v1.2.3 || fail "the tag was not pushed" -for p in obsidian-vithanco vscode-vithanco; do - grep -qx "workflow run ci.yml --repo Vithanco/$p -f vgraph_ref=v1.2.3 -f release_version=1.2.3" "$GH_LOG" \ - || fail "$p was not started: $(cat "$GH_LOG")" -done -grep -q 'vgraph-mcp-node' "$GH_LOG" && fail "started vgraph-mcp-node, which has no repo of its own" - -# Given a version that is not plain semver, when releasing, then nothing happens. -# A leading v would double up in the tag and reach Obsidian, which rejects it. -for bad in v1.2.3 1.2 1.2.3-rc1 "" 'x;y' 01.2.3 1.02.3 1.2.03; do - given_a_clean_main - run "$bad" && fail "accepted version '$bad'" - refused "version '$bad'" -done - -# Given zeros that semver allows, when releasing, then they are accepted. -given_a_clean_main -run 0.10.0 || fail "refused 0.10.0: $(cat "$ROOT/out")" -tag_pushed v0.10.0 || fail "v0.10.0 was not pushed" - -# Given a dirty tree, when releasing, then nothing happens: the tag would not describe it. -given_a_clean_main -echo dirty >> "$REPO/plugins.json" -run 1.2.3 && fail "released from a dirty tree" -refused "dirty tree" - -# Given another branch, when releasing, then nothing happens. -given_a_clean_main -git -C "$REPO" switch -qc feature -run 1.2.3 && fail "released from a branch other than main" -refused "other branch" - -# Given unpushed work, when releasing, then nothing happens: CI could not check it out by its history. -given_a_clean_main -git -C "$REPO" commit -q --allow-empty -m unpushed -run 1.2.3 && fail "released a commit origin does not have" -refused "unpushed commit" - -# Given main behind origin, when releasing, then nothing happens. -given_a_clean_main -OTHER="$ROOT/$CASE-other" -git clone -q "$ORIGIN" "$OTHER" && git -C "$OTHER" commit -q --allow-empty -m newer && git -C "$OTHER" push -q origin main -run 1.2.3 && fail "released a stale main" -refused "stale main" - -# Given the tag already on origin, when releasing, then it is refused and not moved. -given_a_clean_main -git -C "$REPO" tag v1.2.3 && git -C "$REPO" push -q origin v1.2.3 && git -C "$REPO" tag -d v1.2.3 >/dev/null -git -C "$REPO" commit -q --allow-empty -m later && git -C "$REPO" push -q origin main -before=$(git -C "$ORIGIN" rev-parse v1.2.3) -run 1.2.3 && fail "re-released an existing tag" -[ "$(git -C "$ORIGIN" rev-parse v1.2.3)" = "$before" ] || fail "moved an existing tag" -grep -q 'workflow run' "$GH_LOG" && fail "started a build for an existing tag" - -# Given a plugin without the workflow, when releasing, then no tag is pushed. -given_a_clean_main -GH_VIEW_FAILS=1 run 1.2.3 && fail "released with a plugin workflow missing" -refused "missing workflow" - -# Given a tag pushed but a start that fails, when releasing, then it says so and how to retry. -given_a_clean_main -GH_RUN_FAILS=1 run 1.2.3 && fail "reported success though a plugin build did not start" -tag_pushed v1.2.3 || fail "the tag should stand" -grep -q 'gh workflow run ci.yml' "$ROOT/out" || fail "does not say how to start the build by hand: $(cat "$ROOT/out")" - -[ "$FAILED" -eq 0 ] && echo "✓ release-engine" -exit "$FAILED" diff --git a/vgraph-mcp-node/package.json b/vgraph-mcp-node/package.json index 6a58353..17987be 100644 --- a/vgraph-mcp-node/package.json +++ b/vgraph-mcp-node/package.json @@ -1,6 +1,6 @@ { "name": "@vithanco/vgraph-mcp", - "version": "1.0.10", + "version": "1.0.11", "mcpName": "com.vithanco/vgraph-mcp", "description": "Concept Maps, IBIS, Causal Loop Diagrams and Timelines as images. Runs locally via WebAssembly.", "type": "module", diff --git a/vgraph-mcp-node/server.json b/vgraph-mcp-node/server.json index 6a1ca4f..51c0489 100644 --- a/vgraph-mcp-node/server.json +++ b/vgraph-mcp-node/server.json @@ -6,13 +6,13 @@ "url": "https://github.com/Vithanco/VGraph", "source": "github" }, - "version": "1.0.10", + "version": "1.0.11", "websiteUrl": "https://vithanco.com", "packages": [ { "registryType": "npm", "identifier": "@vithanco/vgraph-mcp", - "version": "1.0.10", + "version": "1.0.11", "transport": { "type": "stdio" }