From b9eae47925dad37ff38efeb91a2fc733df13f0df Mon Sep 17 00:00:00 2001 From: James Maes Date: Sat, 25 Apr 2026 11:19:49 -0500 Subject: [PATCH] =?UTF-8?q?test(05-02):=20RED=20=E2=80=94=20PasteboardRead?= =?UTF-8?q?er=20test=20scaffold=20for=20MCP-03=20refusal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Six unit tests covering the refusal matrix: - fileURL + string both present → .refusedFileURL (model-coercion vector) - fileURL only → .refusedFileURL - string only (no fileURL) → .text(content) - empty string → .empty - nil string + non-fileURL type → .empty - nil types → .empty Tests use a MockPasteboard conforming to a PasteboardLike protocol so the reader is testable without touching NSPasteboard.general (which would require a GUI session and pollute test runs). Build fails because PasteboardReader + PasteboardLike + ClipboardReadResult do not yet exist — GREEN step adds them next. --- mcp-servers/mcp-clipboard/Package.swift | 35 ++++++++++ .../Sources/mcp-clipboard/main.swift | 2 + .../PasteboardReaderTests.swift | 70 +++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 mcp-servers/mcp-clipboard/Package.swift create mode 100644 mcp-servers/mcp-clipboard/Sources/mcp-clipboard/main.swift create mode 100644 mcp-servers/mcp-clipboard/Tests/PasteboardReaderTests/PasteboardReaderTests.swift diff --git a/mcp-servers/mcp-clipboard/Package.swift b/mcp-servers/mcp-clipboard/Package.swift new file mode 100644 index 0000000..c3c241b --- /dev/null +++ b/mcp-servers/mcp-clipboard/Package.swift @@ -0,0 +1,35 @@ +// swift-tools-version:6.0 +// +// Package: mcp-clipboard +// +// MCP helper exposing a single `get_clipboard` tool. Refuses pasteboards that +// carry NSPasteboardTypeFileURL (MCP-03) regardless of accompanying string +// content — refusal precedes string extraction so a model can't coerce a +// path read by attaching a friendly-looking string to a fileURL pasteboard. +// +// Built and shipped as a separately-codesigned nested .app bundle under +// Jarvis.app/Contents/Helpers/mcp-clipboard.app/. Plan 05-02. + +import PackageDescription + +let package = Package( + name: "mcp-clipboard", + platforms: [.macOS(.v13)], + dependencies: [ + .package(url: "https://github.com/modelcontextprotocol/swift-sdk", exact: "0.12.0"), + ], + targets: [ + .executableTarget( + name: "mcp-clipboard", + dependencies: [ + .product(name: "MCP", package: "swift-sdk"), + ], + swiftSettings: [.swiftLanguageMode(.v6)] + ), + .testTarget( + name: "PasteboardReaderTests", + dependencies: ["mcp-clipboard"], + swiftSettings: [.swiftLanguageMode(.v6)] + ) + ] +) diff --git a/mcp-servers/mcp-clipboard/Sources/mcp-clipboard/main.swift b/mcp-servers/mcp-clipboard/Sources/mcp-clipboard/main.swift new file mode 100644 index 0000000..69df5e0 --- /dev/null +++ b/mcp-servers/mcp-clipboard/Sources/mcp-clipboard/main.swift @@ -0,0 +1,2 @@ +// mcp-clipboard/main.swift — stub. Replaced in TDD GREEN step. +print("mcp-clipboard stub") diff --git a/mcp-servers/mcp-clipboard/Tests/PasteboardReaderTests/PasteboardReaderTests.swift b/mcp-servers/mcp-clipboard/Tests/PasteboardReaderTests/PasteboardReaderTests.swift new file mode 100644 index 0000000..a546c6b --- /dev/null +++ b/mcp-servers/mcp-clipboard/Tests/PasteboardReaderTests/PasteboardReaderTests.swift @@ -0,0 +1,70 @@ +// PasteboardReaderTests.swift +// +// MCP-03 unit coverage: the PasteboardReader returns `.refusedFileURL` +// whenever the pasteboard's types contain `.fileURL`, regardless of whether a +// `.string` variant is also present. This is the core mitigation for +// T-05-02-01 (model-coercion via fileURL+string pasteboard). +// +// Plan 05-02 / Task 2 (TDD). + +import XCTest +import AppKit +@testable import mcp_clipboard + +/// Stand-in for `NSPasteboard.general` in tests; lets us seed pasteboard state +/// without touching the host's real pasteboard or requiring a GUI session. +struct MockPasteboard: PasteboardLike { + let types: [NSPasteboard.PasteboardType]? + let storedString: String? + + func string(forType type: NSPasteboard.PasteboardType) -> String? { + type == .string ? storedString : nil + } +} + +final class PasteboardReaderTests: XCTestCase { + + // MCP-03: refusal MUST trigger when fileURL is present, even if a friendly + // string also appears. This is the most likely model-coercion vector. + func test_returnsRefusedFileURL_whenTypesContainsFileURL() { + let reader = PasteboardReader( + pasteboard: MockPasteboard(types: [.fileURL, .string], storedString: "innocent string") + ) + XCTAssertEqual(reader.read(), .refusedFileURL) + } + + func test_returnsRefusedFileURL_whenOnlyFileURL() { + let reader = PasteboardReader( + pasteboard: MockPasteboard(types: [.fileURL], storedString: nil) + ) + XCTAssertEqual(reader.read(), .refusedFileURL) + } + + func test_returnsText_whenStringPresent_andNoFileURL() { + let reader = PasteboardReader( + pasteboard: MockPasteboard(types: [.string], storedString: "hello") + ) + XCTAssertEqual(reader.read(), .text("hello")) + } + + func test_returnsEmpty_whenStringIsEmpty() { + let reader = PasteboardReader( + pasteboard: MockPasteboard(types: [.string], storedString: "") + ) + XCTAssertEqual(reader.read(), .empty) + } + + func test_returnsEmpty_whenStringIsNil_andNoFileURL() { + let reader = PasteboardReader( + pasteboard: MockPasteboard(types: [.html], storedString: nil) + ) + XCTAssertEqual(reader.read(), .empty) + } + + func test_returnsEmpty_whenTypesIsNil() { + let reader = PasteboardReader( + pasteboard: MockPasteboard(types: nil, storedString: nil) + ) + XCTAssertEqual(reader.read(), .empty) + } +}