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
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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::"
Expand Down
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.4.1
6.4.2
7 changes: 4 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -93,8 +93,9 @@ that; they are not a pattern to copy for new code.

Unicode normalization tables are linked from
`<xctoolchain>/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.
Expand Down
37 changes: 34 additions & 3 deletions Sources/VGraph/Domain/Attributes/Attribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
} 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 {
Expand All @@ -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: ",") + "]"
}

}
18 changes: 2 additions & 16 deletions Sources/VGraphvizLib/Domain/DotExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
15 changes: 15 additions & 0 deletions Tests/VGraphTests/AttributeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<VRect>(
Expand Down
17 changes: 5 additions & 12 deletions VGraphWasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>/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.
17 changes: 17 additions & 0 deletions VGraphWasm/Tests-Browser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-<ver>.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.
13 changes: 13 additions & 0 deletions VGraphWasm/Tests-Browser/obsidian/playwright.config.js
Original file line number Diff line number Diff line change
@@ -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 },
});
Loading
Loading