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
3 changes: 2 additions & 1 deletion docs/challenges.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ or pass --force to remove it anyway (those communities reject every publication

Otherwise it deletes the directory and reloads the daemon.

The reason: pkc-js can't load a challenge whose name is no longer registered. A running community keeps advertising the old challenge but rejects every publication (`One of the community challenges is misconfigured`), and on its next start (including a daemon restart) `start()` throws and the community stays offline until its settings are changed.
The reason: pkc-js can't load a challenge whose name is no longer registered. A running community keeps advertising the old challenge and stays up, but rejects every publication (`One of the community challenges is misconfigured: challenge "<name>" is not registered on this node`) and emits `ERR_COMMUNITY_CHALLENGES_FAILED_TO_LOAD`. On its next start (including a daemon restart) `start()` fails with `ERR_COMMUNITY_CHALLENGES_FAILED_TO_LOAD` and the community stays offline until its settings are changed or the package is installed again.

- **Only `name` entries count.** An entry with a `path` loads that file, so it doesn't use the package.
- **A package named after a pkc-js built-in** (`question`, `text-math`, `fail`, `blacklist`, `whitelist`, `publication-match`) is refused the same way. Removing it hands the built-in back, so nothing breaks, but those communities switch to the built-in challenge. The refusal says so.
Expand All @@ -120,6 +120,7 @@ The reason: pkc-js can't load a challenge whose name is no longer registered. A
- **Install fails with "No valid package.json found in the archive":** the spec did not produce an npm package tarball.
- **Install fails validation:** the default export is not a challenge factory. A page sort package belongs under `bitsocial page-sort install`.
- **Daemon log `Failed to load challenge "<name>"`:** the package is installed but its entry point throws on import. It is left out of the registry until fixed. A previously loaded version keeps serving.
- **A community fails to start with `ERR_COMMUNITY_CHALLENGES_FAILED_TO_LOAD`** (publishers see `challenge "<name>" is not registered on this node`): an entry in its `settings.challenges` names a challenge this daemon doesn't have, usually a package that was removed with `--force` or never installed on this node. The error's `details.failures` lists each entry and `details.availableChallengeNames` lists what is registered. Reinstall the package with `bitsocial challenge install`, or change the entry with `bitsocial community edit`, then start the community again (`bitsocial community start <address>`).
- **`install` printed no `reloaded ...` line:** no daemon answered at `--pkcRpcUrl`. Pass the URL the daemon actually listens on, including the auth key path for a remote daemon, or restart the daemon.

## Writing a challenge package
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"@oclif/plugin-help": "6.2.36",
"@oclif/plugin-not-found": "3.2.73",
"@oclif/table": "0.5.1",
"@pkcprotocol/pkc-js": "0.0.115",
"@pkcprotocol/pkc-js": "0.0.118",
"dataobject-parser": "1.2.22",
"decompress": "4.2.1",
"env-paths": "2.2.1",
Expand Down
12 changes: 5 additions & 7 deletions test/cli/challenge-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ describe("challenge integration tests", { timeout: 600_000 }, () => {

const sub = await pkc.createCommunity();
await sub.edit({ settings: { challenges: [{ name }] } });
// Once the package is gone, pkc-js with pkcprotocol/pkc-js#429 emits ERR_COMMUNITY_CHALLENGES_FAILED_TO_LOAD
// on the running community; an unhandled "error" event would throw
// Once the package is gone, pkc-js emits ERR_COMMUNITY_CHALLENGES_FAILED_TO_LOAD on the running community
// (pkcprotocol/pkc-js#429); an unhandled "error" event would throw
sub.on("error", () => {});
await sub.start();
expect(await waitForCondition(() => !!(sub as any).updatedAt, 60000, 500)).toBe(true);
Expand All @@ -559,16 +559,14 @@ describe("challenge integration tests", { timeout: 600_000 }, () => {
expect(sub.challenges).toEqual([{ challenge: "7+7", type: "text/plain" }]);
const result = await publishCommentWithChallenge({ pkc, communityAddress: sub.address, challengeAnswer: "14" });
expect(result.challengeSuccess).toBe(false);
expect(result.reason).toContain("One of the community challenges is misconfigured");
expect(result.reason).toContain(`One of the community challenges is misconfigured: challenge "${name}" is not registered on this node`);

// A restart (or a daemon restart) can't load the challenge, so the community goes offline. pkc-js keeps that
// on purpose but names the error (pkcprotocol/pkc-js#429): once a release with it is installed, start()
// rejects with ERR_COMMUNITY_CHALLENGES_FAILED_TO_LOAD and the publish reason above names the challenge, so
// update these assertions in that bump
// on purpose and names the error (pkcprotocol/pkc-js#429)
await sub.stop();
const restarted = await pkc.createCommunity({ address: sub.address });
restarted.on("error", () => {});
await expect(restarted.start()).rejects.toThrow(/expected function, received undefined/);
await expect(restarted.start()).rejects.toMatchObject({ code: "ERR_COMMUNITY_CHALLENGES_FAILED_TO_LOAD" });
expect(await waitForCondition(() => restarted.startedState === "failed", 20000, 200)).toBe(true);
});
});
Expand Down
Loading