Repository navigation
chore: address plugin scanner lint findings #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Local dependencies and generated packaging output | ||
| node_modules/ | ||
| *.tgz | ||
|
|
||
| # Local scratch and notes | ||
| tasks/ | ||
| .DS_Store |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| version: 2 | ||
| updates: | ||
| - package-ecosystem: "npm" | ||
| directory: "/" | ||
| schedule: | ||
| interval: "weekly" | ||
| open-pull-requests-limit: 10 | ||
|
|
||
| - package-ecosystem: "github-actions" | ||
| directory: "/" | ||
| schedule: | ||
| interval: "weekly" | ||
| open-pull-requests-limit: 10 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Security Policy | ||
|
|
||
| ## Supported Versions | ||
|
|
||
| Security fixes are applied to the latest release on `main`. | ||
|
|
||
| | Version | Supported | | ||
| | --- | --- | | ||
| | Latest release | Yes | | ||
| | Older releases | No | | ||
|
|
||
| ## Reporting a Vulnerability | ||
|
|
||
| Please do not report security vulnerabilities in public GitHub issues. | ||
|
|
||
| Use one of the following channels instead: | ||
|
|
||
| 1. Open a private vulnerability report through GitHub Security Advisories for this repository, if that option is available to you. | ||
| 2. Email [jin.ku@sendbird.com](mailto:jin.ku@sendbird.com) with: | ||
| - a description of the issue | ||
| - affected files or flows | ||
| - reproduction steps or proof of concept | ||
| - any suggested mitigation | ||
|
|
||
| Sendbird will review the report and respond as quickly as possible. When a report is confirmed, fixes will be developed on the latest supported version and coordinated for disclosure. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { assertVersionsMatch } from "./lib/version-sync.mjs"; | ||
|
|
||
| try { | ||
| const version = assertVersionsMatch(); | ||
| process.stdout.write( | ||
| `Version sync OK: package.json and .codex-plugin/plugin.json are both ${version}.\n` | ||
| ); | ||
| } catch (error) { | ||
| const message = error instanceof Error ? error.message : String(error); | ||
| process.stderr.write(`${message}\n`); | ||
| process.exitCode = 1; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import fs from "node:fs"; | ||
| import path from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| const ROOT_DIR = path.resolve(fileURLToPath(new URL("../..", import.meta.url))); | ||
|
|
||
| export function resolveVersionSyncPaths(rootDir = ROOT_DIR) { | ||
| return { | ||
| rootDir, | ||
| packageJsonPath: path.join(rootDir, "package.json"), | ||
| pluginJsonPath: path.join(rootDir, ".codex-plugin", "plugin.json"), | ||
| }; | ||
| } | ||
|
|
||
| function readJson(filePath) { | ||
| return JSON.parse(fs.readFileSync(filePath, "utf8")); | ||
| } | ||
|
|
||
| function writeJson(filePath, value) { | ||
| fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`, "utf8"); | ||
| } | ||
|
|
||
| export function readVersionPair(rootDir = ROOT_DIR) { | ||
| const { packageJsonPath, pluginJsonPath } = resolveVersionSyncPaths(rootDir); | ||
| const packageJson = readJson(packageJsonPath); | ||
| const pluginJson = readJson(pluginJsonPath); | ||
| return { | ||
| packageJson, | ||
| pluginJson, | ||
| packageVersion: String(packageJson.version ?? ""), | ||
| pluginVersion: String(pluginJson.version ?? ""), | ||
| }; | ||
| } | ||
|
|
||
| export function assertVersionsMatch(rootDir = ROOT_DIR) { | ||
| const { packageVersion, pluginVersion } = readVersionPair(rootDir); | ||
| if (!packageVersion || !pluginVersion) { | ||
| throw new Error( | ||
| "Both package.json and .codex-plugin/plugin.json must declare a version." | ||
| ); | ||
| } | ||
| if (packageVersion !== pluginVersion) { | ||
| throw new Error( | ||
| `Version mismatch: package.json is ${packageVersion} but .codex-plugin/plugin.json is ${pluginVersion}.` | ||
| ); | ||
| } | ||
| return packageVersion; | ||
| } | ||
|
|
||
| export function syncPluginVersionFromPackage(rootDir = ROOT_DIR) { | ||
| const { pluginJsonPath } = resolveVersionSyncPaths(rootDir); | ||
| const { packageJson, pluginJson, packageVersion, pluginVersion } = | ||
| readVersionPair(rootDir); | ||
|
|
||
| if (!packageVersion) { | ||
| throw new Error("package.json is missing a version."); | ||
| } | ||
|
|
||
| if (packageVersion === pluginVersion) { | ||
| return { changed: false, version: packageVersion }; | ||
| } | ||
|
|
||
| const nextPluginJson = { | ||
| ...pluginJson, | ||
| version: packageJson.version, | ||
| }; | ||
| writeJson(pluginJsonPath, nextPluginJson); | ||
| return { changed: true, version: packageVersion }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { syncPluginVersionFromPackage } from "./lib/version-sync.mjs"; | ||
|
|
||
| try { | ||
| const result = syncPluginVersionFromPackage(); | ||
| process.stdout.write( | ||
| result.changed | ||
| ? `Updated .codex-plugin/plugin.json to version ${result.version}.\n` | ||
| : `.codex-plugin/plugin.json already matches package.json at ${result.version}.\n` | ||
| ); | ||
| } catch (error) { | ||
| const message = error instanceof Error ? error.message : String(error); | ||
| process.stderr.write(`${message}\n`); | ||
| process.exitCode = 1; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { describe, it } from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
| import fs from "node:fs"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
|
|
||
| import { | ||
| assertVersionsMatch, | ||
| readVersionPair, | ||
| syncPluginVersionFromPackage, | ||
| } from "../scripts/lib/version-sync.mjs"; | ||
|
|
||
| function writeJson(filePath, value) { | ||
| fs.mkdirSync(path.dirname(filePath), { recursive: true }); | ||
| fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`, "utf8"); | ||
| } | ||
|
|
||
| function createTempRepo({ packageVersion, pluginVersion }) { | ||
| const dir = fs.mkdtempSync(path.join(os.tmpdir(), "cc-version-sync-")); | ||
| writeJson(path.join(dir, "package.json"), { | ||
| name: "cc-plugin-codex", | ||
| version: packageVersion, | ||
| }); | ||
| writeJson(path.join(dir, ".codex-plugin", "plugin.json"), { | ||
| name: "cc", | ||
| version: pluginVersion, | ||
| }); | ||
| return dir; | ||
| } | ||
|
|
||
| describe("version sync", () => { | ||
| it("asserts the live repo versions match", () => { | ||
| assert.equal(assertVersionsMatch(), "1.0.0"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This assertion hardcodes the repository version to Useful? React with 👍 / 👎. |
||
| }); | ||
|
|
||
| it("detects mismatched versions", () => { | ||
| const dir = createTempRepo({ | ||
| packageVersion: "1.2.3", | ||
| pluginVersion: "1.2.2", | ||
| }); | ||
| try { | ||
| assert.throws( | ||
| () => assertVersionsMatch(dir), | ||
| /Version mismatch: package\.json is 1\.2\.3 but \.codex-plugin\/plugin\.json is 1\.2\.2\./ | ||
| ); | ||
| } finally { | ||
| fs.rmSync(dir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| it("syncs plugin.json from package.json", () => { | ||
| const dir = createTempRepo({ | ||
| packageVersion: "2.0.0", | ||
| pluginVersion: "1.0.0", | ||
| }); | ||
| try { | ||
| const result = syncPluginVersionFromPackage(dir); | ||
| assert.deepEqual(result, { changed: true, version: "2.0.0" }); | ||
| const { packageVersion, pluginVersion } = readVersionPair(dir); | ||
| assert.equal(packageVersion, "2.0.0"); | ||
| assert.equal(pluginVersion, "2.0.0"); | ||
| } finally { | ||
| fs.rmSync(dir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| it("does nothing when versions already match", () => { | ||
| const dir = createTempRepo({ | ||
| packageVersion: "3.1.4", | ||
| pluginVersion: "3.1.4", | ||
| }); | ||
| try { | ||
| const result = syncPluginVersionFromPackage(dir); | ||
| assert.deepEqual(result, { changed: false, version: "3.1.4" }); | ||
| } finally { | ||
| fs.rmSync(dir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
versionlifecycle script syncs.codex-plugin/plugin.jsonbut never stages that change, sonpm versionwill create a tag/commit without the synced plugin file. npm’s ownnpm-versioncommand docs state that files generated inversionscripts must be explicitly added (e.g., viagit add) before the commit step, and without that this leaves a dirty working tree and can publish or push a commit wherepackage.jsonand plugin metadata diverge.Useful? React with 👍 / 👎.