Skip to main content
coreydaley.dev

Testing Purrchiver's Shortcuts actions through the system

Purrchiver has 15 Shortcuts actions, and every one of them had tests. Those tests called each action’s code directly, with a file URL in hand. Shortcuts doesn’t do that. It finds the action by name, in another process, and hands over whatever the previous step produced.

So I ran them through the same App Intents path Shortcuts uses, with App Intents Testing, which is new in macOS 27. It found two bugs the unit tests couldn’t see, and one of them was a side effect of my own fix for an App Review rejection in June. A separate look at what happens when you cancel a shortcut found a third. All three fixes ship in the next Purrchiver release; none of them is in 1.1.1.

What the unit tests skipped

Each action is an AppIntent whose perform() hands the real work to a static helper, such as InspectArchiveIntent.inspect(fileURL:password:). The unit tests call the helpers. That’s quick and it covers the archive work, but it skips everything the system does before perform(): finding the intent, resolving its parameters from what it’s given, and building the files it receives. How Purrchiver is tested is about the archive engine; the Shortcuts actions are the one part of the app other software calls, and none of their tests called them that way.

App Intents Testing

App Intents Testing runs an app’s intents out of process, through the same App Intents stack Shortcuts and Siri use, without linking the app. It launches the app but never touches its windows. A test asks for an intent by name, gives it parameters, runs it, and reads back the value it returned:

let d = launch(.locked)
let result = try await d.intents["InspectArchiveIntent"]
    .makeIntent(archive: IntentFile(fileURL: simpleZip)).run()
let entries: [AnyAppEntity] = try result.value

launch starts the app from a UI test with a flag that forces it locked or unlocked, then returns IntentDefinitions(bundleIdentifier:) for it. The intents run in the app the test launched.

The first question was whether a test can pass a file at all, since every action takes one and the documentation doesn’t say. It can: IntentFile converts like any other parameter value, and the sandboxed app reads the fixture. There’s one limit. The harness can’t answer an action that asks for a value. When an encrypted archive needs a password, the run ends with “The App Intent requested value for parameter ‘password’”, which is enough to check that the action asked.

The tests sit in the UI test bundle, gated on macOS 27, and run on the Mac mini, which is on macOS 27. The app itself still supports macOS 14.6.

Bug one: a file handed over as data

In the test run, when one action’s output went into another, the second action refused it as unreadable.

This traces back to June. App Review rejected Purrchiver 1.0 under Guideline 2.4.5(i) for leaving Shortcuts output in the app’s container, and the fix was to return every output file as data:

return IntentFile(data: data, filename: name)

An IntentFile made that way has no file URL. Most actions’ input still started like this:

guard let url = archive.fileURL else {
    throw ArchiveIntentError.unreadableFile
}

So the outputs and the inputs stopped matching, and nothing noticed, because no test passed one action’s output to another. Three actions failed in odder ways. Verify Checksums treated a Checksum File given that way as missing and asked for it. Create Archive and Repair Archive read their file lists with compactMap(\.fileURL), so a file with no URL was dropped without a word.

That’s what the harness does with a chained file. I haven’t confirmed that Shortcuts hands one over the same way, but an action shouldn’t depend on it either way.

The fix is a small type, IntentInputs, that every action now uses. A file with a URL is read where it is. A file without one is written to a private, owner-only temp folder under its own name, and the folder is removed when the action ends. If the app quits first, the cleanup that removes intent temp folders more than an hour old gets it the next time an action runs. A name like ../escape.zip can’t leave that folder. Yes, that’s a copy in the container again, but a brief one that’s gone when the action finishes, not a result left for the user to find. Unit tests cover each of those cases, and the system tests now pass files between actions in four places.

Bug two: an archive with one file in it

Extract Archive on an archive holding a single file returned no files and no error.

An archive of one file extracts to that file, not to a folder. The code that gathers an action’s output only looked inside folders, and walking a file found nothing. Now a file at the top is returned as itself, under the same size limit as everything else. A unit test extracts a one-file ZIP made with zip and gets the file back, and the system tests’ encrypted ZIP holds a single file too.

What the system tests check now

With the app locked, the free actions run on real files, checked against other tools where there’s one to compare with: Extract Archive against ditto, Decompress File against gunzip, and Recover Archive on a ZIP cut off at 60%, which must return the first file whole. Compress File and Create Archive feed Decompress File and Inspect Archive, and an encrypted ZIP asks for its password and opens with it.

With the app unlocked, each paid action is checked by the action that undoes or verifies it: Encrypt File then Decrypt File, Generate Checksums then Verify Checksums, and Add Recovery Data then Repair Archive on a copy with 20 bytes flipped, which must come back identical to the original.

Seven paid cases must refuse with the unlock message when the app is locked, among them Compress File as xz and Create Archive as 7z or with a password. And the four actions that only read (Inspect, Verify Archive, Recover and Repair) must leave their source with the same size, date and SHA-256.

A cancel that didn’t cancel

This one didn’t come from the harness. Alongside the system tests I opened a second question: what happens when someone cancels a running action in Shortcuts? I hadn’t checked.

Each action runs as a job in the app’s job queue, and the job runs in a task of its own. The action waited on the job, and cancelling the action never touched the job’s task. So a cancelled action ran to the end, and its result was thrown away. If a job did end cancelled, the action reported it as an engine error. The fix forwards the cancel:

return try await withTaskCancellationHandler {
    guard let result = try await handle.get() else { throw CancellationError() }
    return result
} onCancel: {
    handle.resultTask.cancel()
}

I also went through every action that writes a file and recorded what a cancel left behind. Most removed their working folder on any error. Compress File and Create Archive (writing to temp, the default) removed it only for the archive engine’s own errors, so a cancel left a part-written file behind until the hour-old cleanup. They now remove it on any failure. No action touched its source.

The tests for this are unit tests. One cancels a job that would sleep for 50 seconds and expects it to stop within 10, end as a cancel, and show as cancelled in the queue. The other two cancel Compress File’s and Create Archive’s helpers directly, not through perform(), and expect no new temp folder and unchanged sources.

What I got wrong

  • I fixed the output and never tested the hand-off. The June change was right for App Review, and its test checked that perform() left nothing behind. But it built its inputs from file URLs, so it couldn’t see that the next action would refuse the result. That mismatch has been in every release since 1.0.
  • “Also shows they’re free” is only partly true. My commit says running the free actions locked also shows they’re free. Decrypt File, Verify Checksums and Repair Archive are free, but the tests run them unlocked, because their inputs come from paid actions. Nothing shows those three work without the unlock.
  • I planned to adopt CancellableIntent, and didn’t need it. It tells an intent why it was cancelled: by the user or by a timeout. On macOS an intent has no time limit and isn’t suspended after a cancel, so the reason changes nothing. Swift’s own cancellation handler does the job, back to macOS 14.6.
  • The plan asked for a cancel test for every writing action. There are tests for the shared job path and for the two actions that were wrong. The others were recorded as already cleaning up, not tested.

What’s still not tested

  • Compare Archives only has its locked refusal checked. No test runs a comparison through the system.
  • Create Archive and Repair Archive with a data-only file. Those were two of the odder cases, and only the unit tests for IntentInputs cover them. The system tests hand both of them files on disk.
  • The App Shortcuts list, the Siri and Spotlight phrases, has no check.
  • Cancelling through the system. The cancel tests call the job code and helpers directly.
  • The Shortcuts app itself. These tests use the same App Intents stack, not Shortcuts’ editor or runner.
  • Anything before macOS 27, which is where App Intents Testing starts.

The unit tests answered “does the archive work?” The system tests answer “does the action work when something else calls it?” Only the second question found these two bugs.

If your app has Shortcuts actions, does any test hand one a file that isn’t on disk?

Related posts