diff --git a/CHANGELOG.md b/CHANGELOG.md index 331f939..ec7a752 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.2.1] - 2026-10-12 + +### Fixed +- `generate --json`: a sign failure caused by the device being keyed for another app now reports `KEY_MISMATCH` with a fix (run again with the rekey), instead of the device's "Failed: Invalid Password." and an unrelated `--package-only` hint. +- `generate --json`: `packagePath` in the result is always absolute, even when the project's output path is relative. + ## [1.2.0] - 2026-10-11 ### Added diff --git a/README.md b/README.md index aa2ed5e..8e3e1cd 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ Steps are `home`, `build`, `validate`, `rekey`, `deploy`, `sign` and `save`. A f `{"type":"result","ok":false,"step":"rekey","code":"REKEY_FAILED","message":"...","hint":"..."}`. Error codes: `PROJECT_NOT_FOUND`, `DEVICE_UNREACHABLE`, `AUTH_FAILED`, `NEEDS_BUILD_CHOICE`, `TASK_NOT_FOUND`, `BUILD_FAILED`, `BUILD_TIMEOUT`, `INVALID_BUILD`, `SIGNED_PKG_MISSING`, `REKEY_FAILED`, `DEPLOY_FAILED`, -`DEPLOY_TIMEOUT`, `SIGN_FAILED`, `CANCELLED`, `UNKNOWN`. Exit code is 0 on success, 1 on failure, 130 when cancelled. +`DEPLOY_TIMEOUT`, `SIGN_FAILED`, `KEY_MISMATCH`, `CANCELLED`, `UNKNOWN`. Exit code is 0 on success, 1 on failure, 130 when cancelled. With no build flag, `--json` uses the project's `defaultBuildTask`; if it has none and VSCode tasks exist, it fails with `NEEDS_BUILD_CHOICE`. diff --git a/package-lock.json b/package-lock.json index 134ad7d..365b9c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "roku-pkg-cli", - "version": "1.2.0", + "version": "1.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "roku-pkg-cli", - "version": "1.2.0", + "version": "1.2.1", "license": "MIT", "dependencies": { "archiver": "^7.0.1", diff --git a/package.json b/package.json index 93f8e8c..a556d02 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "roku-pkg-cli", - "version": "1.2.0", + "version": "1.2.1", "description": "A comprehensive CLI tool for managing multiple Roku projects with automated device discovery, build integration, and package generation. Perfect for CI/CD pipelines with full automation support.", "main": "dist/index.js", "bin": { diff --git a/src/lib/events.ts b/src/lib/events.ts index 19957cf..3e4c749 100644 --- a/src/lib/events.ts +++ b/src/lib/events.ts @@ -4,7 +4,7 @@ export type Step = 'home' | 'build' | 'validate' | 'rekey' | 'deploy' | 'sign' | export type ErrorCode = | 'PROJECT_NOT_FOUND' | 'DEVICE_UNREACHABLE' | 'AUTH_FAILED' | 'NEEDS_BUILD_CHOICE' | 'TASK_NOT_FOUND' | 'BUILD_FAILED' | 'BUILD_TIMEOUT' | 'INVALID_BUILD' | 'SIGNED_PKG_MISSING' - | 'REKEY_FAILED' | 'DEPLOY_FAILED' | 'DEPLOY_TIMEOUT' | 'SIGN_FAILED' | 'CANCELLED' | 'UNKNOWN'; + | 'REKEY_FAILED' | 'DEPLOY_FAILED' | 'DEPLOY_TIMEOUT' | 'SIGN_FAILED' | 'KEY_MISMATCH' | 'CANCELLED' | 'UNKNOWN'; export type StepStatus = 'start' | 'done' | 'skip' | 'fail'; export type PkgEvent = | { type: 'step'; step: Step; status: StepStatus; ms?: number; detail?: string } diff --git a/src/lib/generate-json.ts b/src/lib/generate-json.ts index a3a1965..428cf9a 100644 --- a/src/lib/generate-json.ts +++ b/src/lib/generate-json.ts @@ -128,6 +128,8 @@ export async function runGenerateJson(opts: GenerateJsonOptions, emitter: Emitte const project = opts.project ? deps.config.getProject(opts.project) : undefined; if (!project) return fail('PROJECT_NOT_FOUND', `Project '${opts.project ?? ''}' not found.`, 'Run roku-pkg list to see the configured projects.'); const configured = deps.config.getRokuDevice(); + // Relative output paths resolve against the working directory; report and use the absolute path. + const outputLocation = path.resolve(project.outputLocation); const host = opts.host || configured.ip; const password = opts.password ?? configured.password; @@ -211,10 +213,21 @@ export async function runGenerateJson(opts: GenerateJsonOptions, emitter: Emitte const downloadDir = path.join(os.tmpdir(), `roku-pkg-out-${process.pid}`); try { const remote = await deps.sign({ host, password, rootDir: tempDir, signingPassword: project.signKey }); - local = await deps.retrieve(remote, { host, password, outDir: downloadDir, outFile: path.basename(project.outputLocation, '.pkg') }); + local = await deps.retrieve(remote, { host, password, outDir: downloadDir, outFile: path.basename(outputLocation, '.pkg') }); } catch (e) { checkCancel(); - fail('SIGN_FAILED', (e as Error).message, 'Packaging needs the app deployed on the device; run without --package-only.'); + const msg = (e as Error).message; + // The device signs with the key it was last rekeyed with; another app's key rejects this sign key. + if (/invalid password/i.test(msg)) { + fail( + 'KEY_MISMATCH', + `The device is keyed for a different app, so it rejected ${project.name}'s sign key.`, + opts.skipRekey + ? `Run again without skipping the rekey, so the device gets ${project.name}'s key.` + : `Check that the sign key matches ${path.basename(project.signPackageLocation)}, then run again.` + ); + } + fail('SIGN_FAILED', msg, opts.packageOnly ? 'Package only needs the app already deployed on the device; run again without Package only.' : undefined); } finally { if (!local) deps.removeDir(downloadDir); } @@ -222,13 +235,13 @@ export async function runGenerateJson(opts: GenerateJsonOptions, emitter: Emitte checkCancel(); start('save'); - deps.mkdirp(path.dirname(project.outputLocation)); - deps.copyFile(local, project.outputLocation); + deps.mkdirp(path.dirname(outputLocation)); + deps.copyFile(local, outputLocation); deps.removeDir(downloadDir); done('save'); await deps.home(host).catch(() => undefined); - emitter.emit({ type: 'result', ok: true, packagePath: project.outputLocation, sizeBytes: deps.size(project.outputLocation), version: deps.readVersion(project.rootDir) }); + emitter.emit({ type: 'result', ok: true, packagePath: outputLocation, sizeBytes: deps.size(outputLocation), version: deps.readVersion(project.rootDir) }); return 0; } catch (e) { const err = opts.signal?.aborted diff --git a/tests/unit/generate-json.test.ts b/tests/unit/generate-json.test.ts index f260cae..c17a22a 100644 --- a/tests/unit/generate-json.test.ts +++ b/tests/unit/generate-json.test.ts @@ -117,4 +117,33 @@ describe('runGenerateJson', () => { expect(outDirs[0]).not.toBe('/out'); expect(events.at(-1)).toMatchObject({ ok: false, code: 'SIGN_FAILED' }); }); + it('reports an absolute package path even when outputLocation is relative', async () => { + const deps = fakeDeps({ config: { getProject: () => ({ ...project, outputLocation: './output/CNBC.pkg' }), getRokuDevice: () => ({ ip: '', password: '' }) } }); + const { events } = await run({}, deps); + expect(events.at(-1)).toMatchObject({ ok: true, packagePath: require('path').resolve('./output/CNBC.pkg') }); + }); + + it('explains a key mismatch when rekey was skipped', async () => { + const deps = fakeDeps({ sign: async () => { throw new Error('Failed: Invalid Password.'); } }); + const { events } = await run({ skipRekey: true }, deps); + const r = events.at(-1) as { code: string; step: string; message: string; hint: string }; + expect(r.code).toBe('KEY_MISMATCH'); + expect(r.step).toBe('sign'); + expect(r.message).toMatch(/keyed for a different app/); + expect(r.hint).toMatch(/rekey/i); + expect(r.hint).not.toMatch(/package-only/); + }); + + it('explains a key mismatch even after a rekey', async () => { + const deps = fakeDeps({ sign: async () => { throw new Error('Failed: Invalid Password.'); } }); + const { events } = await run({}, deps); + expect(events.at(-1)).toMatchObject({ code: 'KEY_MISMATCH', step: 'sign' }); + }); + + it('only suggests a deploy for other sign failures when package-only was used', async () => { + const deps = fakeDeps({ sign: async () => { throw new Error('No app to package'); } }); + expect((await run({}, deps)).events.at(-1)).toMatchObject({ code: 'SIGN_FAILED' }); + expect(((await run({}, deps)).events.at(-1) as { hint?: string }).hint ?? '').not.toMatch(/package-only/); + expect(((await run({ packageOnly: true }, deps)).events.at(-1) as { hint?: string }).hint).toMatch(/package only/i); + }); });