test(05-02): RED — PasteboardReader test scaffold for MCP-03 refusal

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.
This commit is contained in:
james.maes committed 2026-04-25 11:19:49 -05:00
1 parent 06bae38cc9
commit b9eae47925
3 files changed
+107

No files matched your search

+35
View File
@@ -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)]
)
]
)
@@ -0,0 +1,2 @@
// mcp-clipboard/main.swift — stub. Replaced in TDD GREEN step.
print("mcp-clipboard stub")
@@ -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)
}
}