Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ jobs:
with:
go-version-file: go.mod
cache: true
- uses: actions/setup-node@v4
with:
node-version: 24
- name: Test
run: go test ./...
run: npm test

build:
name: Build ${{ matrix.goos }}/${{ matrix.goarch }}
Expand Down
Empty file modified bin/opencode-manager
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"scripts": {
"build": "go build -o dist/opencode-manager-$(node -p \"process.platform\")-$(node -p \"process.arch\") ./cmd/opencode-manager",
"test": "go test ./...",
"test": "go test ./... && node --test scripts/verify-package.test.js",
"prepack": "node scripts/verify-package.js",
"postinstall": "node scripts/postinstall.js"
},
Expand Down
36 changes: 29 additions & 7 deletions scripts/verify-package.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
const fs = require("node:fs");
const path = require("node:path");

const packageRoot = path.resolve(__dirname, "..");
const binaries = [
"opencode-manager-linux-x64",
"opencode-manager-linux-arm64",
"opencode-manager-darwin-x64",
"opencode-manager-darwin-arm64",
];

const missing = binaries.filter((binary) => !fs.existsSync(path.join(packageRoot, "dist", binary)));
const launchers = ["bin/ocm", "bin/opencode-manager"];
function packageErrors(packageRoot) {
const errors = [];
const missing = binaries.filter((binary) => !fs.existsSync(path.join(packageRoot, "dist", binary)));
if (missing.length > 0) {
errors.push("Cannot pack opencode-manager; missing prebuilt binaries:", ...missing.map((binary) => ` dist/${binary}`));
}

const invalidLaunchers = launchers.filter((launcher) => {
try {
const stat = fs.statSync(path.join(packageRoot, launcher));
return !stat.isFile() || (stat.mode & 0o111) === 0;
} catch {
return true;
}
});
if (invalidLaunchers.length > 0) {
errors.push("Cannot pack opencode-manager; launchers must be executable files:", ...invalidLaunchers.map((launcher) => ` ${launcher}`));
}

if (missing.length > 0) {
console.error("Cannot pack opencode-manager; missing prebuilt binaries:");
for (const binary of missing) {
console.error(` dist/${binary}`);
return errors;
}

if (require.main === module) {
const errors = packageErrors(path.resolve(__dirname, ".."));
if (errors.length > 0) {
console.error(errors.join("\n"));
process.exit(1);
}
process.exit(1);
}

module.exports = { packageErrors };
48 changes: 48 additions & 0 deletions scripts/verify-package.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const assert = require("node:assert/strict");
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const test = require("node:test");

const { packageErrors } = require("./verify-package");

const binaries = [
"opencode-manager-linux-x64",
"opencode-manager-linux-arm64",
"opencode-manager-darwin-x64",
"opencode-manager-darwin-arm64",
];

function packageFixture(t) {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "opencode-manager-package-"));
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
fs.mkdirSync(path.join(root, "bin"));
fs.mkdirSync(path.join(root, "dist"));
for (const binary of binaries) {
fs.writeFileSync(path.join(root, "dist", binary), "");
}
for (const launcher of ["ocm", "opencode-manager"]) {
fs.writeFileSync(path.join(root, "bin", launcher), "#!/usr/bin/env node\n", { mode: 0o755 });
}
return root;
}

test("packageErrors accepts executable launcher files", (t) => {
assert.deepEqual(packageErrors(packageFixture(t)), []);
});

test("packageErrors rejects a non-executable launcher", (t) => {
const root = packageFixture(t);
fs.chmodSync(path.join(root, "bin", "opencode-manager"), 0o644);

assert.match(packageErrors(root).join("\n"), /bin\/opencode-manager/);
});

test("packageErrors rejects a launcher directory", (t) => {
const root = packageFixture(t);
const launcher = path.join(root, "bin", "ocm");
fs.unlinkSync(launcher);
fs.mkdirSync(launcher);

assert.match(packageErrors(root).join("\n"), /bin\/ocm/);
});
Loading