Testing & Signing
A plugin has two gates before users can run it: the tests you write, and the Ed25519 signature that proves the publisher and protects the package from modification. This page covers both.
Unit tests
Plugins are Android application modules, so unit tests live in src/test/kotlin and run on the JVM with JUnit 4. Add the test dependencies to the module:
dependencies {
testImplementation("io.github.sadami3066.sora:plugin-api:2.0.2")
testImplementation("junit:junit:4.13.2")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.11.0")
testImplementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.12.0")
testImplementation(platform("androidx.compose:compose-bom:2026.03.00"))
testImplementation("androidx.compose.runtime:runtime")
testImplementation("androidx.compose.ui:ui")
testImplementation("androidx.compose.foundation:foundation")
testImplementation("androidx.compose.material3:material3")
}Run the suite with:
./gradlew :testDebugUnitTestThe official plugin repository runs ./scripts/check.sh to test, sign, and verify every module; CI uses the same tasks for pull requests.
What to test
| Area | Approach |
|---|---|
| Pure logic | Extract formatting, parsing, prompt text, and state transitions into top-level functions and test them directly |
| Localized copy | Call the function once per language and assert language-specific fragments; assert no CJK characters leak into English output |
| Tool behavior | Build the tool with pluginTool(...) and execute it with a fake PluginToolCall inside runTest |
| Host-dependent code | Hide host calls behind your own interfaces, or implement a fake PluginHost |
| JSON payloads | Parse PluginToolResult.details/card payloads and assert the expected keys |
Example: test a tool through the real factory and a fake call.
import io.github.sadami3066.sora.plugin.api.PluginRunSignal
import io.github.sadami3066.sora.plugin.api.PluginToolCall
import io.github.sadami3066.sora.plugin.api.PluginToolResult
import kotlinx.coroutines.test.runTest
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
import org.junit.Assert.assertEquals
import org.junit.Test
private class FakeCall(
override val args: kotlinx.serialization.json.JsonObject,
override val sessionId: String = "test-session",
) : PluginToolCall {
override val callId: String = "call-1"
override val signal: PluginRunSignal? = PluginRunSignal.None
val partials = mutableListOf<PluginToolResult>()
override fun partial(result: PluginToolResult) {
partials += result
}
}
class GreetingToolTest {
private val tool = greetingTool()
@Test
fun greetsTheProvidedName() = runTest {
val call = FakeCall(buildJsonObject { put("name", "Ada") })
val result = tool.execute(call)
assertEquals("Hello, Ada!", result.text)
assertEquals(false, result.isError)
}
@Test
fun reportsMissingNameAsError() = runTest {
val result = tool.execute(FakeCall(buildJsonObject { }))
assertEquals(true, result.isError)
}
}Faking the host
PluginHost has five properties and 36 service accessors. Implement the ones your test uses and throw PluginServiceUnavailable from the rest:
import android.content.Context
import io.github.sadami3066.sora.plugin.api.*
import java.io.File
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
internal open class FakeHost : PluginHost {
override val manifest: PluginManifest get() = unavailable("manifest")
override val context: Context get() = unavailable("context")
override val dataDir: File get() = unavailable("dataDir")
override val assetsDir: File get() = unavailable("assetsDir")
override val scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Unconfined)
override fun text(source: LocalizedText, vararg args: Any): String = source.resolve("en") ?: ""
override fun logs(): LogService = object : LogService {
override fun log(level: PluginLogLevel, message: String, error: Throwable?) = Unit
}
override fun settings(): PluginSettingsService = InMemorySettings()
override fun linux(): LinuxService = unavailable("linux")
override fun screen(): ScreenService = unavailable("screen")
// ... the remaining accessors
private fun unavailable(name: String): Nothing = throw PluginServiceUnavailable(name)
}
class InMemorySettings : PluginSettingsService {
private val values = mutableMapOf<String, String>()
override suspend fun get(key: String): String? = values[key]
override suspend fun put(key: String, value: String) { values[key] = value }
override suspend fun remove(key: String) { values.remove(key) }
override suspend fun clear() { values.clear() }
override suspend fun keys(): Set<String> = values.keys
override suspend fun snapshot(): Map<String, String> = values.toMap()
override suspend fun getJson(key: String): JsonObject? =
values[key]?.let { Json.parseToJsonElement(it) as? JsonObject }
override suspend fun putJson(key: String, value: JsonObject) { values[key] = value.toString() }
override fun observe(key: String?): Flow<Map<String, String>> = flowOf(values.toMap())
}Then test contributions with plugin.contributions(FakeHost()), skills with plugin.skills(FakeHost()), and so on. Compose slot content is harder to test without an instrumentation setup; keep rendering logic thin and move computations into plain functions.
Signing keys
The signing key is an Ed25519 key pair stored as two PEM files sharing a base path:
keys/plugin-signing.pem PKCS#8 private key ("BEGIN PRIVATE KEY")
keys/plugin-signing.pub X.509 SubjectPublicKeyInfo ("BEGIN PUBLIC KEY")Generate with the template task
./gradlew generateSigningKeyThe template creates keys/plugin-signing.pem and .pub, narrows the private key permissions, and refuses to overwrite an existing pair. Delete both files to regenerate — but read the warning below first.
The official plugin repository does not ship a key-generation task; its keys are provisioned from the maintainer secret store, and the shared build script fails with instructions when a key is missing.
Generate with OpenSSL
openssl genpkey -algorithm ED25519 -out plugin-signing.pem
openssl pkey -in plugin-signing.pem -pubout -out plugin-signing.pub
chmod 600 plugin-signing.pemEd25519 needs JDK 15 or newer; the plugin toolchain uses JDK 17, so the platform provider is always available.
Read the publisher keyId
The keyId is the SHA-256 of the DER-encoded public key:
openssl pkey -pubin -in plugin-signing.pub -outform DER | sha256sum
# keyId = "ed25519:" + the 64-character lowercase hex digestsignPlugin prints the same value. Marketplace entries and the install confirmation use it as the publisher fingerprint.
Where the tasks look for the key
| Priority | Source | Notes |
|---|---|---|
| 1 | -PpluginSigningKey=<base> | Highest priority; a base path without .pem/.pub |
| 2 | SORA_PLUGIN_SIGNING_KEY | Environment variable with the same base path |
| 3 | $SORA_SECRETS_DIR/plugin-signing | A secrets directory, used if the .pem exists there |
| 4 | ~/.config/sora/secrets/plugin-signing | Default local secret location |
| 5 | <rootProject>/keys/plugin-signing | Repository default |
The shared script used by official plugins implements all five; the template task supports -PpluginSigningKey with the keys/plugin-signing default. Keep the private key outside the repository or gitignored, and never commit it: whoever holds it can publish updates as that publisher.
CI provisioning
CI stores the private key PEM as a secret (PLUGIN_SIGNING_KEY for release builds), stages it into a temporary directory, derives the public key, and passes the base path to Gradle:
printf '%s\n' "$PLUGIN_SIGNING_KEY" > "$RUNNER_TEMP/plugin-signing.pem"
chmod 600 "$RUNNER_TEMP/plugin-signing.pem"
openssl pkey -in "$RUNNER_TEMP/plugin-signing.pem" -pubout -out "$RUNNER_TEMP/plugin-signing.pub"
./gradlew verifyPlugin -PpluginSigningKey="$RUNNER_TEMP/plugin-signing"Pull-request CI never touches the real key: it generates an ephemeral Ed25519 pair, publishes plugin-api and design to mavenLocal, and runs the signing check with that throwaway key. This proves the packaging and signing pipeline works without granting the secret.
Rules for keys:
- One publisher key per publisher, not per plugin: all plugins you publish should share it.
- Back the
.pemup. If it is lost, existing installs can no longer receive updates — a new key is a new publisher. - Never pass the key through command-line arguments in CI logs, and never print it.
- Rotate only by accepting a new publisher identity; the marketplace will record a new
publisherKeyId.
Verify a signed bundle
./gradlew verifyPluginThe task reads META-INF/plugin-signature.json, recomputes the canonical entry digest, checks keyId, and verifies the Ed25519 signature. Success prints:
Signature OK: build/plugin/my-plugin.ddp (keyId=ed25519:...)signPlugin also self-verifies the package it just wrote before reporting success, and prints the publisher keyId, whole-package SHA-256, and entry digest. Record the keyId and package SHA-256 for release metadata.
What verifyPlugin proves and does not prove:
| Proves | Does not prove |
|---|---|
| The archive content matches the signed digest | The manifest passes host validation |
The keyId matches the public key in the signature file | The host will accept the API level or minimum host version |
| The private key corresponding to that public key signed this bundle | The bundle matches what the marketplace entry points to |
Host validation (ids, versions, capabilities, permissions, components, slots) runs at install time and reports specific codes; see Manifest & Packaging → Validation codes.
Signature details
For the full format, see Manifest & Packaging → Signature specification. The critical invariants:
- The signed message is the canonical entry digest: every non-
META-INF/entry, sorted by UTF-8 byte order of the entry name, one line per entry:<sha256> <uncompressed-size> <name>\n. keyIdmust equaled25519:plus the SHA-256 of the DER public key; the host recomputes it and rejects mismatches.- The whole-package SHA-256 is recorded at install and re-checked before every load, so a bundle modified in place is rejected even before signature verification.
- Updates must reuse the publisher key. A different key is treated as a different publisher and cannot upgrade an existing install.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
missing signing key: .../plugin-signing.pem | Wrong base path, or the key pair was never generated | Pass -PpluginSigningKey=<base> or generate the pair; check that both .pem and .pub exist next to the base path |
InvalidKeyException / EncodedKeySpec error | The PEM is not a PKCS#8 Ed25519 private key (for example an EC or RSA key) | Regenerate with openssl genpkey -algorithm ED25519 or generateSigningKey |
signed bundle failed self-verification | The .pub does not belong to the .pem, or files were edited | Regenerate the pair from one source; never mix halves from different keys |
| Install: signature error | The .ddp was modified after signing, entries were repacked with different names/sizes, or META-INF/plugin-signature.json is missing | Sign the exact archive that ships; do not re-zip a signed bundle |
| Install: publisher mismatch | The new version is signed with a different key | Reuse the original private key; a lost key cannot be replaced for existing installs |
Install: keyId mismatch | The signature file was hand-edited, or keyId was copied from another key | Re-run signPlugin; never edit the signature JSON |
verifyPlugin passes but install fails | Manifest validation, version conflict, or a tool name conflict | Read the install error code and check validation codes |
| Signature enters a different hash each build | APK rebuilds are not byte-identical | Expected: sign the artifact you publish, then compute and publish its SHA-256 |
Ed25519 not available | A JDK older than 15 is running Gradle | Run Gradle with JDK 17 |
Dependencies between signing and packaging:
signPlugindepends onassemblePlugin; re-runningverifyPluginre-runs assemble, sign, and verify in order.assemblePlugindepends onassembleDebugand packs the debug APK. The plugin module does not ship a release APK; minification is disabled in both build types.- Fixed entry timestamps make the unsigned package deterministic for the same APK, but the signed package always contains the signature entry, so its SHA-256 differs from the unsigned one.
