From 0ab00b9f5e36d9ea371970fef4b04905d50fa4c0 Mon Sep 17 00:00:00 2001 From: leemour Date: Thu, 19 Nov 2026 14:01:20 +0100 Subject: [PATCH 1/2] fix(content): an Author or Contributor syncs their own posts again WordPress refuses both roles the pages list with a private status (HTTP 400, 403 inside), and that refusal failed the whole post sync: after the first run, edits on the site never reached the copy. cli-core 0.710.0 adds optional.needs: the pages call now needs capabilities.edit_pages and is skipped with a gap otherwise; pages check edit_others_pages, not edit_others_posts. Docs say what each role gets now, the roadmap item is done, and a test per role syncs through the CLI against the fake: the pages are never asked for, and an edit made after the first sync arrives. Checked live on the Docker WordPress 6.9.4 (author1, contrib): sync is complete, own posts in the copy, a title edit through wp-cli arrives. Co-Authored-By: Claude Opus 5.5 --- README.md | 7 ++--- changes/fix-content-roles.md | 5 ++++ docs/index.md | 6 ++--- docs/roadmap.md | 2 -- docs/troubleshooting.md | 4 +-- docs/usage.md | 9 ++++--- package.json | 2 +- pnpm-lock.yaml | 10 ++++---- skills/wordpress-cli/SKILL.md | 4 +-- src/content-contracts.test.ts | 45 +++++++++++++++++++++++++++++++++ src/generated/wirecat-config.ts | 18 ++++++++++--- wirecat.config.ts | 29 ++++++++++++++------- 12 files changed, 106 insertions(+), 35 deletions(-) create mode 100644 changes/fix-content-roles.md diff --git a/README.md b/README.md index ede8b90..ee51ba5 100644 --- a/README.md +++ b/README.md @@ -186,9 +186,10 @@ More: [permissions](https://github.com/WireCatLabs/wordpress-cli/blob/main/docs/ - Only self-hosted WordPress with application passwords. WordPress.com sites, which sign in with OAuth, are not supported. Sign-in through the browser is not there yet: you paste the password. -- An Author or Contributor gets only part of the site. WordPress refuses the pages list to both, so the posts sync - stays partial and changes on the site do not reach the copy. A Contributor also sees only their own posts. Only an - Administrator gets the users list. Sign in as an Administrator for a full copy. +- An Author or Contributor gets only their own posts, and no pages: WordPress refuses the pages list to both, and the + sync says so. A Contributor gets only their drafts and posts waiting for review. For both, a post deleted for good + on the site stays in the copy. Only an Administrator gets the users list. Sign in as an Administrator for a full + copy. - No view counts. WordPress itself keeps none, and Jetpack stats are not supported. - A post with galleries, columns, embeds or iframes keeps its body: `posts update` changes its title, excerpt, tags and status only, unless you add `--replace-body`. diff --git a/changes/fix-content-roles.md b/changes/fix-content-roles.md new file mode 100644 index 0000000..c46b13a --- /dev/null +++ b/changes/fix-content-roles.md @@ -0,0 +1,5 @@ +### Fixed + +- **An Author or Contributor sign-in syncs their own posts again.** WordPress refuses both roles the pages list, and + that refusal stopped the whole sync of posts: after the first run, changes on the site no longer reached the copy. + The sync now skips the pages for a role without the right to edit pages, says so in its gaps, and copies the posts. diff --git a/docs/index.md b/docs/index.md index 6a00726..f80438f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -121,9 +121,9 @@ password. - Only self-hosted WordPress with application passwords. WordPress.com sites are not supported. - You paste the application password. Sign-in through the browser is on the [roadmap](roadmap.md). -- An Author or Contributor gets only part of the site. WordPress refuses the pages list to both, so the posts sync - stays partial and changes on the site do not reach the copy. A Contributor also sees only their own posts. Only an - Administrator gets the users list. Sync reports each of these as a gap. +- An Author or Contributor gets only their own posts, and no pages: WordPress refuses the pages list to both. A + Contributor gets only their drafts and posts waiting for review. For both, a post deleted for good on the site + stays in the copy. Only an Administrator gets the users list. Sync reports each of these as a gap. - No view counts. WordPress itself keeps none, and Jetpack stats are not supported. `posts stats` shows only what the copy has. - Plugin fields, such as those of SEO or custom field plugins, have no flags. The `api` group sends them in a raw diff --git a/docs/roadmap.md b/docs/roadmap.md index 9393606..7ff40c1 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -24,8 +24,6 @@ and trash a post, each with its own permission. `wordpress blog api` reaches eve ## Next -- **Full sync for Authors and Contributors.** Copy what an Author or Contributor may read, without stopping at the - pages list. - **Sign in with the browser.** Approve the tool in wp-admin, in place of pasting an application password. - **Plugin fields.** Read and set common plugin fields, such as an SEO title, without a raw `--body`. diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 2f68151..6b6ad9a 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -34,8 +34,8 @@ wordpress blog session status --check # asks your site whose password it is | No **Application Passwords** section in your profile | The site needs WordPress 5.7 or later over https, and a plugin or the host may turn the section off. Ask the site's admin. | | A WordPress.com address | WordPress.com sites are not supported, only self-hosted WordPress. | | `posts list` is empty | Run `wordpress blog sync` first. Posts are read from the copy it makes. | -| `sync` ends partial, or pages are missing | An Author or Contributor sign-in cannot list pages, and a Contributor sees only their own posts. Only an Administrator lists the users. Sign in as an Administrator for a full copy, or as an Editor for every post and page. | -| A change on the site is missing from the copy | Run `sync`. If it still ends partial, see the row above. | +| `sync` names gaps, or pages are missing | An Author or Contributor sign-in cannot list pages and gets only their own posts; a Contributor only their drafts and posts waiting for review. Only an Administrator lists the users. Sign in as an Administrator for a full copy, or as an Editor for every post and page. | +| A change on the site is missing from the copy | Run `sync`. If the post is not yours and you sign in as an Author or Contributor, see the row above. | | `content.conflict` | The post changed on the site since the last sync. Run `sync`, look at the post again, then retry. | | `content.lossy-body` | The post has galleries, columns, embeds or iframes that Markdown cannot keep. Change only its title, excerpt, tags or status, or add `--replace-body` to write the body anyway and flatten them. See [when a write stops](usage.md#when-a-write-stops). | | `content.schedule-past` | `--at-time` must be ahead of now. | diff --git a/docs/usage.md b/docs/usage.md index ea97cbd..161eb25 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -48,10 +48,11 @@ tags and categories, and the users who write. A post's text is kept as Markdown. Later syncs ask WordPress only for posts changed since then. Once a day a sync also finds the posts the site deleted for good. A post in the trash stays in the copy, with its status. -A sync can end partial and still succeed: it names each gap. With an Author or Contributor sign-in, WordPress -refuses the pages list, so the posts stay partial and changes on the site do not reach the copy. A Contributor also -sees only their own posts. Only an Administrator gets the users list, so an Editor's copy has every post and page but -no users. Sign in as an Administrator for a full copy. +A sync names each gap: what your WordPress role may not read. With an Author or Contributor sign-in, the sync copies +your own posts and skips the pages, as WordPress refuses the pages list to both. A Contributor gets only their drafts +and posts waiting for review. For both, a post deleted for good on the site stays in the copy, while one in the trash +shows as trashed. Only an Administrator gets the users list, so an Editor's copy has every post and page but no +users. Sign in as an Administrator for a full copy. `--max-pages` caps the requests in one run. The next sync goes on from where it stopped. diff --git a/package.json b/package.json index eda1096..58d62d2 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ }, "dependencies": { "@wirecat/cli-base": "0.124.0", - "@wirecat/cli-core": "0.707.0", + "@wirecat/cli-core": "0.710.0", "commander": "15.0.0", "valibot": "1.5.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a57d613..05e8c40 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,8 +16,8 @@ importers: specifier: 0.124.0 version: 0.124.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5) '@wirecat/cli-core': - specifier: 0.707.0 - version: 0.707.0(@wirecat/cli-base@0.124.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5))(commander@15.0.0)(typescript@7.0.2)(zod@4.6.7) + specifier: 0.710.0 + version: 0.710.0(@wirecat/cli-base@0.124.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5))(commander@15.0.0)(typescript@7.0.2)(zod@4.6.7) commander: specifier: 15.0.0 version: 15.0.0 @@ -1213,8 +1213,8 @@ packages: '@wirecat/cli-core-sqlite@1.1.0': resolution: {integrity: sha512-GpGlh/dAIX/nblBYCdT6DfWSLFxav9mxxeELQAfEuw+QZdT9unKxbi5xa02s/s4JS1P7n0PQx2sCABj4FlMRNw==} - '@wirecat/cli-core@0.707.0': - resolution: {integrity: sha512-+8fERPdNxm5g+PZrk+B9DzYhTMTXFQYovzzG2XpTBZkpn5pCjKOu9solPZrCUAkyNmUssKhYHv+QvB/9Fmmmrw==} + '@wirecat/cli-core@0.710.0': + resolution: {integrity: sha512-cZ/eLpANwnL6JyDa/YmmRDCpNEKwbMLjE2OhGKLW8U6itxRCRjF64xYl6C30R9OpqFz/ZvkTLmNuzb+Iqrszwg==} engines: {node: ^22.16.0 || >=24} hasBin: true peerDependencies: @@ -3360,7 +3360,7 @@ snapshots: '@wirecat/cli-core-sqlite@1.1.0': {} - '@wirecat/cli-core@0.707.0(@wirecat/cli-base@0.124.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5))(commander@15.0.0)(typescript@7.0.2)(zod@4.6.7)': + '@wirecat/cli-core@0.710.0(@wirecat/cli-base@0.124.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5))(commander@15.0.0)(typescript@7.0.2)(zod@4.6.7)': dependencies: '@anthropic-ai/sdk': 1.3.0(zod@4.6.7) '@bomb.sh/tab': 0.0.22(commander@15.0.0) diff --git a/skills/wordpress-cli/SKILL.md b/skills/wordpress-cli/SKILL.md index 99b3e9b..554cabd 100644 --- a/skills/wordpress-cli/SKILL.md +++ b/skills/wordpress-cli/SKILL.md @@ -46,8 +46,8 @@ unless the task says. `type:page`, `tag:`, `author:`, `published:` with a time, `>=`, or `[a TO b]`. - **Ids are strings.** Pass them back unchanged. - **Missing is not absent.** A sync can be partial and still exit `0`: read `complete` and its gaps. An Author or - Contributor sign-in cannot list pages, a Contributor sees only their own posts, and only an Administrator lists the - users. Say so when it matters, and do not claim a post is not there. + Contributor sign-in gets only their own posts and no pages, and only an Administrator lists the users. Say so when + it matters, and do not claim a post is not there. - **No view counts.** WordPress keeps none. `posts stats` holds only what the store has. ## Write and publish diff --git a/src/content-contracts.test.ts b/src/content-contracts.test.ts index a237d34..a561314 100644 --- a/src/content-contracts.test.ts +++ b/src/content-contracts.test.ts @@ -139,3 +139,48 @@ it("sync before session start says to sign in, and sends nothing", async () => { expect(unsigned.json()).toMatchObject({ error: { code: "authentication_error" } }) expect(sent).toEqual([]) }) + +// What WordPress 6.9.4 gives each role (checked on a local site): no right to edit others' posts or any page, and no +// users list. The pages list with a private status is refused to both, HTTP 400 with 403 in its details. +const ROLES = { + author: ["edit_others_posts", "edit_pages", "edit_others_pages"], + contributor: ["edit_others_posts", "edit_pages", "edit_others_pages"], +} + +for (const [role, rights] of Object.entries(ROLES)) + it(`${role === "author" ? "An Author" : "A Contributor"} syncs their posts, never asks for the pages, and gets later edits`, async () => { + const keyring = memoryKeyring() + // A store of its own: the file's other tests sync pages into the shared one. + const env = { MESSAGING_STORE: join(mkdtempSync(join(tmpdir(), "content-role-")), "store.db") } + const started = await runCli(["personal", "session", "start", "--site", FAKE_SITE, "--login", login, "--json"], { + keyring, + service: fakeServiceApi(), + stdin: password, + }) + expect(started.code, started.err).toBe(0) + const fake = contentManifestFake(SOURCE, { + api: API.manifest, + lacks: rights.map((one) => `capabilities.${one}`), + denied: ["getWpV2Users"], + }) + fakes.push(fake) + const sync = async () => { + const synced = await runCli(["personal", "sync", "--json"], { keyring, service: fake, env }) + expect(synced.code, synced.err).toBe(0) + return synced.json().item as { state: string; gaps: { scope?: string; message: string }[] } + } + const first = await sync() + expect(first.state).toBe("complete") + expect(first.gaps.find((one) => one.scope === "edit_pages")?.message).toBe( + "only an editor or administrator reads the pages", + ) + const [posts] = fake.rows.post ?? [] + const post = posts?.[0] as { id: number; title: { raw: string } } + post.title = { raw: "Edited on the site" } + fake.touch("post", String(post.id)) + expect((await sync()).state).toBe("complete") + const listed = await runCli(["personal", "posts", "list", "--json"], { keyring, service: fake, env }) + const items = (listed.json() as { items: { external_id: string; type: string; title: string }[] }).items + expect(items.map((one) => one.type)).not.toContain("page") + expect(items.find((one) => one.external_id === String(post.id))?.title).toBe("Edited on the site") + }) diff --git a/src/generated/wirecat-config.ts b/src/generated/wirecat-config.ts index 32d1dfb..f590984 100644 --- a/src/generated/wirecat-config.ts +++ b/src/generated/wirecat-config.ts @@ -180,7 +180,7 @@ export const SOURCE: Readonly> & { }, }, optional: { - message: "the sign-in may not read every post or page: an author or a contributor reads only some", + message: "the sign-in may not read every post: an author or a contributor reads only its own", scope: "edit_others_posts", requires: { operation: "getWpV2UsersMe", @@ -275,15 +275,25 @@ export const SOURCE: Readonly> & { }, }, optional: { - message: "the sign-in may not read every post or page: an author or a contributor reads only some", - scope: "edit_others_posts", + message: "the sign-in may not read every page", + scope: "edit_others_pages", requires: { operation: "getWpV2UsersMe", query: { context: "edit", _fields: "capabilities", }, - check: "capabilities.edit_others_posts", + check: "capabilities.edit_others_pages", + }, + needs: { + operation: "getWpV2UsersMe", + query: { + context: "edit", + _fields: "capabilities", + }, + check: "capabilities.edit_pages", + message: "only an editor or administrator reads the pages", + scope: "edit_pages", }, }, }, diff --git a/wirecat.config.ts b/wirecat.config.ts index 9d065ba..16b9120 100644 --- a/wirecat.config.ts +++ b/wirecat.config.ts @@ -2,6 +2,7 @@ import { defineCli } from "@wirecat/cli-core/manifest" // WordPress's posts and pages: every status, sorted by id to list and by change time to sync. const STATUSES = "publish,future,draft,pending,private,trash" +const ME = { operation: "getWpV2UsersMe", query: { context: "edit", _fields: "capabilities" } } const posts = (operation: string, type: "post" | "page") => { const list = { operation, query: { context: "edit", status: STATUSES, per_page: 100, orderby: "id", order: "asc" } } return { @@ -44,15 +45,25 @@ const posts = (operation: string, type: "post" | "page") => { format: "wp-blocks" as const, fallback: { path: "content.rendered", format: "html" as const }, }, - optional: { - message: "the sign-in may not read every post or page: an author or a contributor reads only some", - scope: "edit_others_posts", - requires: { - operation: "getWpV2UsersMe", - query: { context: "edit", _fields: "capabilities" }, - check: "capabilities.edit_others_posts", - }, - }, + optional: + type === "post" + ? { + message: "the sign-in may not read every post: an author or a contributor reads only its own", + scope: "edit_others_posts", + requires: { ...ME, check: "capabilities.edit_others_posts" }, + } + : { + message: "the sign-in may not read every page", + scope: "edit_others_pages", + requires: { ...ME, check: "capabilities.edit_others_pages" }, + // WordPress refuses an author or a contributor pages with a private status (HTTP 400, 403 inside). + needs: { + ...ME, + check: "capabilities.edit_pages", + message: "only an editor or administrator reads the pages", + scope: "edit_pages", + }, + }, } } From 79eadd8c99ad89183cbbe94f5bc58c7dafa1ce3c Mon Sep 17 00:00:00 2001 From: leemour Date: Thu, 19 Nov 2026 14:05:40 +0100 Subject: [PATCH 2/2] docs(content): what an Author's or Contributor's copy misses; the seed's needs test Review: for these roles every sync reads all their posts again, and a post that leaves their view stays in the copy as it was. The trash claim was not checked live and is gone. The generic seed test (a call's needs lacked is never sent) joins the role tests, as cli-template seeds it. Co-Authored-By: Claude Opus 5.5 --- README.md | 4 ++-- docs/index.md | 4 ++-- docs/usage.md | 7 ++++--- src/content-contracts.test.ts | 27 +++++++++++++++++++++++++++ src/generated/wirecat-config.ts | 2 +- wirecat.config.ts | 2 +- 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ee51ba5..b71e81a 100644 --- a/README.md +++ b/README.md @@ -187,8 +187,8 @@ More: [permissions](https://github.com/WireCatLabs/wordpress-cli/blob/main/docs/ - Only self-hosted WordPress with application passwords. WordPress.com sites, which sign in with OAuth, are not supported. Sign-in through the browser is not there yet: you paste the password. - An Author or Contributor gets only their own posts, and no pages: WordPress refuses the pages list to both, and the - sync says so. A Contributor gets only their drafts and posts waiting for review. For both, a post deleted for good - on the site stays in the copy. Only an Administrator gets the users list. Sign in as an Administrator for a full + sync says so. A Contributor gets only their drafts and posts waiting for review. For both, a post that leaves their + view stays in the copy as it was: one deleted for good, or a Contributor's post an editor published. Only an Administrator gets the users list. Sign in as an Administrator for a full copy. - No view counts. WordPress itself keeps none, and Jetpack stats are not supported. - A post with galleries, columns, embeds or iframes keeps its body: `posts update` changes its title, excerpt, tags diff --git a/docs/index.md b/docs/index.md index f80438f..363efaf 100644 --- a/docs/index.md +++ b/docs/index.md @@ -122,8 +122,8 @@ password. - Only self-hosted WordPress with application passwords. WordPress.com sites are not supported. - You paste the application password. Sign-in through the browser is on the [roadmap](roadmap.md). - An Author or Contributor gets only their own posts, and no pages: WordPress refuses the pages list to both. A - Contributor gets only their drafts and posts waiting for review. For both, a post deleted for good on the site - stays in the copy. Only an Administrator gets the users list. Sync reports each of these as a gap. + Contributor gets only their drafts and posts waiting for review. For both, a post that leaves their view stays in + the copy as it was: one deleted for good, or a Contributor's post an editor published. Only an Administrator gets the users list. Sync reports each of these as a gap. - No view counts. WordPress itself keeps none, and Jetpack stats are not supported. `posts stats` shows only what the copy has. - Plugin fields, such as those of SEO or custom field plugins, have no flags. The `api` group sends them in a raw diff --git a/docs/usage.md b/docs/usage.md index 161eb25..d3f6516 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -50,9 +50,10 @@ for good. A post in the trash stays in the copy, with its status. A sync names each gap: what your WordPress role may not read. With an Author or Contributor sign-in, the sync copies your own posts and skips the pages, as WordPress refuses the pages list to both. A Contributor gets only their drafts -and posts waiting for review. For both, a post deleted for good on the site stays in the copy, while one in the trash -shows as trashed. Only an Administrator gets the users list, so an Editor's copy has every post and page but no -users. Sign in as an Administrator for a full copy. +and posts waiting for review. For both, each sync reads all of your posts again, not only the changes, and a post +that leaves your view stays in the copy as it was: one deleted for good, or a Contributor's post an editor published. +Only an Administrator gets the users list, so an Editor's copy has every post and page but no users. Sign in as an +Administrator for a full copy. `--max-pages` caps the requests in one run. The next sync goes on from where it stopped. diff --git a/src/content-contracts.test.ts b/src/content-contracts.test.ts index a561314..e5ae67d 100644 --- a/src/content-contracts.test.ts +++ b/src/content-contracts.test.ts @@ -140,6 +140,33 @@ it("sync before session start says to sign in, and sends nothing", async () => { expect(sent).toEqual([]) }) +// A call a role may not make names its right in `optional.needs`: a sign-in without it never sends the call (the fake +// would list it in `refusals`), and the sync ends complete with that gap. +type Needs = { check: string; message: string } +const needs = Object.values(SOURCE.entities as Record) + .flat() + .flatMap((entity) => (entity.optional?.needs ? [entity.optional.needs] : [])) + +if (needs.length) + it("a sign-in without a call's right skips that call, says so, and the sync completes", async () => { + const keyring = memoryKeyring() + // A store of its own: the file's other tests sync every call's rows into the shared one. + const env = { MESSAGING_STORE: join(mkdtempSync(join(tmpdir(), "content-needs-")), "store.db") } + const started = await runCli(["personal", "session", "start", "--site", FAKE_SITE, "--login", login, "--json"], { + keyring, + service: fakeServiceApi(), + stdin: password, + }) + expect(started.code, started.err).toBe(0) + const fake = contentManifestFake(SOURCE, { api: API.manifest, lacks: needs.map((one) => one.check) }) + fakes.push(fake) + const synced = await runCli(["personal", "sync", "--json"], { keyring, service: fake, env }) + expect(synced.code, synced.err).toBe(0) + const report = synced.json().item as { state: string; gaps: { message: string }[] } + expect(report.state).toBe("complete") + expect(report.gaps.map((one) => one.message)).toEqual(expect.arrayContaining(needs.map((one) => one.message))) + }) + // What WordPress 6.9.4 gives each role (checked on a local site): no right to edit others' posts or any page, and no // users list. The pages list with a private status is refused to both, HTTP 400 with 403 in its details. const ROLES = { diff --git a/src/generated/wirecat-config.ts b/src/generated/wirecat-config.ts index f590984..8b6f430 100644 --- a/src/generated/wirecat-config.ts +++ b/src/generated/wirecat-config.ts @@ -180,7 +180,7 @@ export const SOURCE: Readonly> & { }, }, optional: { - message: "the sign-in may not read every post: an author or a contributor reads only its own", + message: "the sign-in may not read every post: an author or a contributor reads only their own", scope: "edit_others_posts", requires: { operation: "getWpV2UsersMe", diff --git a/wirecat.config.ts b/wirecat.config.ts index 16b9120..03c6b09 100644 --- a/wirecat.config.ts +++ b/wirecat.config.ts @@ -48,7 +48,7 @@ const posts = (operation: string, type: "post" | "page") => { optional: type === "post" ? { - message: "the sign-in may not read every post: an author or a contributor reads only its own", + message: "the sign-in may not read every post: an author or a contributor reads only their own", scope: "edit_others_posts", requires: { ...ME, check: "capabilities.edit_others_posts" }, }