commit c924244ff4cb3725c79c2f451a366bbddb322152
parent 6a7ba8c64d890df233f9cc7644cea4abab0bd41c
Author: triesap <tyson@radroots.org>
Date: Sat, 10 Oct 2026 00:19:04 +0000
messages: handle unavailable sold and uncertain product requests (HCP-108)
Diffstat:
13 files changed, 874 insertions(+), 37 deletions(-)
diff --git a/web/src/lib/catalog/product-view.ts b/web/src/lib/catalog/product-view.ts
@@ -64,9 +64,20 @@ export type ProductViewSnapshot = Readonly<{
}>;
declare const productBrand: unique symbol;
export type ProductView = Readonly<{ readonly [productBrand]: true }>;
+declare const acknowledgementBrand: unique symbol;
+export type ProductStatusAcknowledgement = Readonly<{
+ readonly [acknowledgementBrand]: true;
+}>;
+const acknowledgements = new WeakMap<
+ ProductStatusAcknowledgement,
+ { view: ProductView; current(this: void): boolean }
+>();
interface Owner {
snapshot: () => ProductViewSnapshot;
- listing: () => ProductListingOwnership | undefined;
+ listing: (
+ acknowledgement?: ProductStatusAcknowledgement
+ ) => ProductListingOwnership | undefined;
+ acknowledge: (review: unknown) => ProductStatusAcknowledgement | undefined;
close: () => void;
}
export type ProductListingOwnership = Readonly<{
@@ -195,11 +206,60 @@ export function createProductView(
else next();
}
const token = Object.freeze({}) as ProductView;
+ function coverageKey(observed: ProductViewSnapshot) {
+ return JSON.stringify({
+ runCurrent: publicViewRunCurrent(view, run),
+ outcome: observed.outcome,
+ eventId: observed.eventId,
+ lastKnown: observed.lastKnown,
+ sources: observed.sources.map((scope) => ({
+ context: scope.result.context,
+ state: scope.state,
+ coverage: scope.result.coverage,
+ sources: scope.result.sources.map(({ source, state }) => ({
+ source,
+ state
+ }))
+ }))
+ });
+ }
owners.set(token, {
snapshot,
- listing() {
+ acknowledge(review) {
const observed = snapshot();
- if (observed.outcome !== 'active' || observed.lastKnown || !head) return;
+ if (
+ review !== 'reviewed_last_known_listing' ||
+ observed.outcome !== 'active' ||
+ !observed.lastKnown ||
+ !observed.eventId ||
+ !head ||
+ closed
+ )
+ return;
+ const key = coverageKey(observed);
+ const consent = Object.freeze({}) as ProductStatusAcknowledgement;
+ acknowledgements.set(consent, {
+ view: token,
+ current: () =>
+ !closed &&
+ publicViewOwnsRun(view, run) &&
+ publicViewProjectionAvailable(view) &&
+ coverageKey(snapshot()) === key
+ });
+ return consent;
+ },
+ listing(acknowledgement) {
+ const observed = snapshot();
+ const capturedConsent =
+ acknowledgement && acknowledgements.get(acknowledgement);
+ const consent =
+ capturedConsent?.view === token ? capturedConsent.current : undefined;
+ if (
+ observed.outcome !== 'active' ||
+ (observed.lastKnown && !consent?.()) ||
+ !head
+ )
+ return;
const selected = publicViewKnownEvidence(view, head).head;
const metadata = publicHeadSnapshot(selected);
if (
@@ -219,7 +279,7 @@ export function createProductView(
return (
!closed &&
actual.outcome === 'active' &&
- !actual.lastKnown &&
+ (!actual.lastKnown || !!consent?.()) &&
actual.eventId === metadata.id
);
}
@@ -316,7 +376,14 @@ export function closeProductView(token: ProductView): void {
// Only the original current view resolves the observed signed proof. Detached
// UI snapshots cannot create this witness or select another author/version.
export function productViewListingOwnership(
- token: ProductView
+ token: ProductView,
+ acknowledgement?: ProductStatusAcknowledgement
): ProductListingOwnership | undefined {
- return owners.get(token)?.listing();
+ return owners.get(token)?.listing(acknowledgement);
+}
+export function acknowledgeProductViewUncertainty(
+ token: ProductView,
+ review: unknown
+): ProductStatusAcknowledgement | undefined {
+ return owners.get(token)?.acknowledge(review);
}
diff --git a/web/src/lib/components/ProductEnquiry.svelte b/web/src/lib/components/ProductEnquiry.svelte
@@ -41,10 +41,14 @@
productRequestSnapshot,
type ProductRequestController
} from '../messaging/product-request-controller.ts';
- import type {
- ProductView,
- ProductViewSnapshot
+ import {
+ acknowledgeProductViewUncertainty,
+ type ProductStatusAcknowledgement,
+ type ProductView,
+ type ProductViewSnapshot
} from '../catalog/product-view.ts';
+ import { enquiryReadinessSnapshot } from '../messaging/enquiry-readiness.ts';
+ import { internalHref } from '../navigation-url.ts';
import {
captureProductEnquiry,
productEnquirySnapshot,
@@ -82,6 +86,16 @@
: { state: 'guest' as const, reason: 'unavailable' as const }
);
let runtime: PublicRuntime | undefined;
+ let acknowledgement = $state.raw<ProductStatusAcknowledgement | undefined>();
+ const readiness = $derived.by(() => {
+ void observation;
+ void identity;
+ return enquiryReadinessSnapshot(
+ view,
+ identityContext && identityViewSession(identityContext),
+ acknowledgement
+ );
+ });
function acquire() {
if (!identityContext) return;
identity = identityViewSnapshot(identityContext).identity;
@@ -147,7 +161,11 @@
});
function open() {
if (draft) closeProductEnquiry(draft);
- draft = captureProductEnquiry(view, 'reviewed_product_enquiry');
+ draft = captureProductEnquiry(
+ view,
+ 'reviewed_product_enquiry',
+ acknowledgement
+ );
captured = draft ? productEnquirySnapshot(draft) : undefined;
if (draft) oncapture?.(draft);
request = draft && createProductRequestController(draft, runtime);
@@ -170,6 +188,22 @@
}
</script>
+{#if readiness.action === 'own'}
+ <p>
+ This is your listing. Manage it rather than sending yourself an enquiry.
+ </p>
+ <a href={internalHref(`/products/${readiness.naddr}/edit`)}>Manage listing</a>
+{:else if readiness.action === 'sold'}
+ <p>
+ The seller marked this listing sold. New requests are unavailable; existing
+ conversations remain in Messages.
+ </p>
+{:else if readiness.action === 'withdrawn'}
+ <p>
+ This listing was withdrawn. New requests are unavailable; existing
+ conversations remain in Messages.
+ </p>
+{/if}
{#if captured}
<section class="stack" aria-label="Product request">
<h2>Message about {captured.title}</h2>
@@ -216,9 +250,24 @@
</p>{/if}
</section>
{:else}
- <Button
- label="Message seller"
- onclick={open}
- disabled={observation?.outcome !== 'active' || observation.lastKnown}
- />
+ {#if readiness.action === 'acknowledgement_required'}
+ <p>
+ The listing status check is incomplete. Availability and these last-known
+ terms may have changed.
+ </p>
+ <Button
+ label="I understand the listing status is uncertain"
+ onclick={() => {
+ acknowledgement = acknowledgeProductViewUncertainty(
+ view,
+ 'reviewed_last_known_listing'
+ );
+ }}
+ />
+ {/if}
+ {#if readiness.action === 'available' || readiness.action === 'acknowledgement_required'}<Button
+ label="Message seller"
+ onclick={open}
+ disabled={readiness.action !== 'available'}
+ />{/if}
{/if}
diff --git a/web/src/lib/messaging/enquiry-readiness.ts b/web/src/lib/messaging/enquiry-readiness.ts
@@ -0,0 +1,106 @@
+import {
+ productViewSnapshot,
+ productViewListingOwnership,
+ type ProductView,
+ type ProductStatusAcknowledgement
+} from '../catalog/product-view.ts';
+import {
+ identitySessionSnapshot,
+ type IdentitySession
+} from '../runtime/identity-session.ts';
+import {
+ inboxResolutionSnapshot,
+ inboxResolverCurrentAfterSample,
+ type InboxResolver
+} from './resolve-inbox.ts';
+import { inboxRelayTargets, type RelayPolicy } from '../config/relays.ts';
+import { inboxPreferenceSnapshot } from '../nostr/inbox-preferences.ts';
+
+export type SellerInboxStatus =
+ 'unchecked' | 'compatible' | 'missing' | 'unsupported' | 'inconclusive';
+// Informational observations of original owners, never Send or route authority.
+export function sellerInboxStatus(
+ resolver: InboxResolver | undefined,
+ author: string,
+ policy?: RelayPolicy
+): SellerInboxStatus {
+ if (!resolver) return 'unchecked';
+ try {
+ const observed = inboxResolutionSnapshot(resolver);
+ if (
+ observed.author !== author ||
+ !inboxResolverCurrentAfterSample(resolver)
+ )
+ return 'inconclusive';
+ if (observed.status === 'ready' && policy) {
+ const preference =
+ observed.head && inboxPreferenceSnapshot(observed.head);
+ if (
+ !preference ||
+ inboxRelayTargets(policy, preference.relays, 'write').length === 0
+ )
+ return 'unsupported';
+ }
+ return observed.status === 'ready' ? 'compatible' : observed.status;
+ } catch {
+ return 'inconclusive';
+ }
+}
+export function sellerInboxCopy(status: SellerInboxStatus): string {
+ return status === 'missing'
+ ? 'In-app messaging is not available for this seller in this prototype.'
+ : status === 'unsupported'
+ ? 'The seller inbox configuration is unsupported in this prototype.'
+ : status === 'inconclusive'
+ ? 'The seller inbox could not be confirmed from the sources checked.'
+ : '';
+}
+export function enquiryReadinessSnapshot(
+ view: ProductView,
+ identity?: IdentitySession,
+ acknowledgement?: ProductStatusAcknowledgement,
+ resolver?: InboxResolver
+): Readonly<{
+ action:
+ | 'unavailable'
+ | 'sold'
+ | 'withdrawn'
+ | 'own'
+ | 'acknowledgement_required'
+ | 'available';
+ naddr?: string;
+ sellerInbox: SellerInboxStatus;
+}> {
+ const blocked = {
+ action: 'unavailable' as const,
+ sellerInbox: 'unchecked' as const
+ };
+ try {
+ const observed = productViewSnapshot(view);
+ const actor = identity && identitySessionSnapshot(identity);
+ const inbox = sellerInboxStatus(resolver, observed.reference.pubkey);
+ const base = { naddr: observed.reference.naddr, sellerInbox: inbox };
+ if (
+ observed.eventId &&
+ actor &&
+ 'publicKey' in actor &&
+ actor.publicKey === observed.reference.pubkey
+ )
+ return { ...base, action: 'own' };
+ if (observed.outcome === 'sold' || observed.outcome === 'withdrawn')
+ return { ...base, action: observed.outcome };
+ if (observed.outcome !== 'active')
+ return { ...base, action: 'unavailable' };
+ const listing = productViewListingOwnership(view, acknowledgement);
+ return {
+ ...base,
+ action: listing?.current()
+ ? 'available'
+ : observed.lastKnown
+ ? 'acknowledgement_required'
+ : 'unavailable'
+ };
+ } catch {
+ return blocked;
+ }
+}
diff --git a/web/src/lib/messaging/product-enquiry.ts b/web/src/lib/messaging/product-enquiry.ts
@@ -1,6 +1,7 @@
import {
productViewListingOwnership,
- type ProductView
+ type ProductView,
+ type ProductStatusAcknowledgement
} from '../catalog/product-view.ts';
import {
captureEnquiryContext,
@@ -37,11 +38,12 @@ const owners = new WeakMap<ProductEnquiry, Owner>();
// inbox readiness nor Send authority, and performs no network/native/SDK call.
export function captureProductEnquiry(
view: ProductView,
- review: unknown
+ review: unknown,
+ acknowledgement?: ProductStatusAcknowledgement
): ProductEnquiry | undefined {
if (typeof window === 'undefined' || review !== 'reviewed_product_enquiry')
return;
- const listing = productViewListingOwnership(view);
+ const listing = productViewListingOwnership(view, acknowledgement);
if (!listing?.current()) return;
const context = captureEnquiryContext(listing.proof);
const observed = context && enquiryContextSnapshot(context);
diff --git a/web/src/lib/messaging/product-request-controller.ts b/web/src/lib/messaging/product-request-controller.ts
@@ -16,6 +16,11 @@ import {
} from './inbox-setup-view.ts';
import { messagingReadinessSnapshot } from './readiness.ts';
import {
+ sellerInboxStatus,
+ sellerInboxCopy,
+ type SellerInboxStatus
+} from './enquiry-readiness.ts';
+import {
createInboxRoutePlan,
inboxRoutePlanSnapshot
} from './inbox-routing.ts';
@@ -91,6 +96,7 @@ type Snapshot = Readonly<{
dirty: boolean;
revision: number;
readyToSend: boolean;
+ sellerInbox: SellerInboxStatus;
copy: string;
saveCopy: string;
pairCopy: string;
@@ -213,7 +219,12 @@ export function createProductRequestController(
? draft.dirty
: !!productEnquirySnapshot(enquiry)?.text.trim(),
revision: actual?.revision ?? 0,
- readyToSend: !attempted && ready(),
+ readyToSend: !attempted && state !== 'needs_action' && ready(),
+ sellerInbox: sellerInboxStatus(
+ resolver,
+ actual!.peer,
+ inboxSetupViewOwnership(setup)?.policy
+ ),
copy:
copy ||
(state === 'preparing'
@@ -288,7 +299,31 @@ export function createProductRequestController(
// Resolver observations are asynchronous; sample their original bounded
// result through the existing readiness projection, without guessing.
await settleInboxResolver(other, admitted);
- if (!admitted()) return { status: 'stopped' };
+ if (!admitted()) {
+ const unavailable = sellerInboxCopy(
+ sellerInboxStatus(other, captured.data.peer, captured.own.policy)
+ );
+ if (
+ unavailable &&
+ current() &&
+ generation === originalGeneration &&
+ identity === actor &&
+ setup === originalSetup &&
+ captured.actor.current() &&
+ captured.own.current() &&
+ privateOwner.current() &&
+ productEnquirySnapshot(enquiry)?.revision === captured.data.revision
+ ) {
+ state = 'needs_action';
+ copy =
+ (captured.product.current()
+ ? ''
+ : 'Listing status changed or could not be confirmed. Review the current listing before sending. ') +
+ unavailable +
+ ' Your unsent text stays in memory.';
+ }
+ return { status: 'stopped' };
+ }
if (
!messagingReadinessSnapshot(
actor,
@@ -298,8 +333,17 @@ export function createProductRequestController(
{ author: captured.data.peer, resolver: other },
captured.own.observeAccess
).sendReady
- )
- return needsAction();
+ ) {
+ const result = needsAction();
+ const unavailable = sellerInboxCopy(
+ sellerInboxStatus(other, captured.data.peer, captured.own.policy)
+ );
+ if (unavailable)
+ copy =
+ unavailable +
+ ' Your unsent text stays in memory. Optional other contact details may be available on the listing.';
+ return result;
+ }
const routes = createInboxRoutePlan(
captured.own.policy,
captured.actor.owner,
diff --git a/web/src/routes/products/[naddr=naddr]/+page.svelte b/web/src/routes/products/[naddr=naddr]/+page.svelte
@@ -144,10 +144,11 @@
{#if result.outcome === 'active'}<p>
Confirm availability with the seller.
</p>
- {#if productOwner}<ProductEnquiry
- view={productOwner}
- observation={result}
- />{/if}{/if}
+ {/if}
+ {#if productOwner}<ProductEnquiry
+ view={productOwner}
+ observation={result}
+ />{/if}
<Disclosure summary="Listing and source details">
{#if result.eventId}<p>
Listing version: <code>{result.eventId}</code>
diff --git a/web/tests/e2e/harness/product-enquiry.ts b/web/tests/e2e/harness/product-enquiry.ts
@@ -131,6 +131,8 @@ export async function renderFixture(existing = false) {
};
},
knownPath: () => (thread ? '/messages/' + thread.knownId : undefined),
+ existingThread: () => thread?.thread(),
+ resolveExistingThread: () => thread?.resolve(thread.knownId),
reuse: () =>
draft && thread
? reuseProductEnquiryConversation(
diff --git a/web/tests/e2e/harness/product-request.ts b/web/tests/e2e/harness/product-request.ts
@@ -32,6 +32,10 @@ import {
createProductView,
productViewSnapshot,
closeProductView,
+ acknowledgeProductViewUncertainty,
+ productViewListingOwnership,
+ type ProductView,
+ type ProductStatusAcknowledgement,
type ProductViewSnapshot
} from '../../../src/lib/catalog/product-view.ts';
import { encodeProductReference } from '../../../src/lib/nostr/references.ts';
@@ -211,6 +215,8 @@ export async function renderFixture(qualified = true) {
for (const callback of observers) callback(value);
}
);
+ let otherView: ProductView | undefined;
+ let retainedConsent: ProductStatusAcknowledgement | undefined;
const target = document.createElement('div');
document.body.append(target);
let draft: ProductEnquiry | undefined,
@@ -304,6 +310,54 @@ export async function renderFixture(qualified = true) {
owner,
peer,
viewSnapshot: () => productViewSnapshot(view),
+ captureUncertain(review: unknown) {
+ const acknowledgement = acknowledgeProductViewUncertainty(view, review);
+ return !!captureProductEnquiry(
+ view,
+ 'reviewed_product_enquiry',
+ acknowledgement
+ );
+ },
+ createOtherView() {
+ otherView = createProductView(
+ createPublicView(runtime),
+ reference,
+ { nowSeconds: () => 1700000200 },
+ () => {}
+ );
+ },
+ otherViewSnapshot: () => otherView && productViewSnapshot(otherView),
+ consentCases() {
+ retainedConsent = acknowledgeProductViewUncertainty(
+ view,
+ 'reviewed_last_known_listing'
+ );
+ return {
+ genuine: !!retainedConsent,
+ current: !!productViewListingOwnership(
+ view,
+ retainedConsent
+ )?.current(),
+ copied: !!productViewListingOwnership(view, {
+ ...retainedConsent
+ } as ProductStatusAcknowledgement),
+ other:
+ !!otherView &&
+ !!productViewListingOwnership(otherView, retainedConsent),
+ otherControl:
+ !!otherView &&
+ !!productViewListingOwnership(
+ otherView,
+ acknowledgeProductViewUncertainty(
+ otherView,
+ 'reviewed_last_known_listing'
+ )
+ )?.current(),
+ unreviewed: !!acknowledgeProductViewUncertainty(view, undefined)
+ };
+ },
+ consentCurrent: () =>
+ !!productViewListingOwnership(view, retainedConsent)?.current(),
identity: () => identityViewSnapshot(context),
setup: () => inboxSetupViewSnapshot(setup),
snapshot: () => controller && productRequestSnapshot(controller),
@@ -419,6 +473,7 @@ export async function renderFixture(qualified = true) {
mode = 'normal';
release?.();
closeProductView(view);
+ if (otherView) closeProductView(otherView);
await unmount(mounted);
closeIdentityView(context);
closePublicRuntime(publicContext);
diff --git a/web/tests/e2e/product-enquiry.spec.ts b/web/tests/e2e/product-enquiry.spec.ts
@@ -202,7 +202,7 @@ async function ready(page: Page, existing = false) {
await page.evaluate(async (existing) => {
window.hcp106Fixture = await window.hcp106.renderFixture(existing);
}, existing);
- await expect(page.locator('[data-enquiry-fixture]')).toBeVisible();
+ await expect(page.locator('[data-enquiry-fixture]')).toBeAttached();
if (existing)
await expect
.poll(() =>
@@ -226,6 +226,27 @@ const open = (page: Page) =>
panel(page)
.getByRole('button', { name: 'Message seller', exact: true })
.click();
+test('HCP108 a sold listing does not remove an original retained conversation or its UUID navigation', async ({
+ page
+}) => {
+ mode = 'sold';
+ await ready(page, true);
+ const actual = await page.evaluate(async () => ({
+ listing: window.hcp106Fixture.viewSnapshot(),
+ thread: window.hcp106Fixture.existingThread(),
+ native: await window.hcp106Fixture.native(),
+ path: await window.hcp106Fixture.resolveExistingThread(),
+ known: window.hcp106Fixture.knownPath()
+ }));
+ expect(actual.listing.outcome).toBe('sold');
+ expect(actual.thread?.status).toBe('ready');
+ expect(actual.thread?.messages.length).toBeGreaterThan(0);
+ expect(actual.native.received.length).toBeGreaterThan(0);
+ expect(actual.native.pairs.length).toBeGreaterThan(0);
+ expect(actual.path).toBe(true);
+ expect(actual.known).toMatch(/^\/messages\/[a-f0-9-]{36}$/);
+ expect(await page.evaluate(() => window.hcp106Fixture.capture())).toBe(false);
+});
test('explicit guest enquiry captures the signed publisher and readable viewed context without connection or Send', async ({
page
}) => {
@@ -408,6 +429,18 @@ for (const rejection of [
async ({ page }) => {
mode = rejection;
await ready(page);
+ expect(
+ await page.evaluate(() => window.hcp106Fixture.viewSnapshot().outcome)
+ ).toBe(
+ rejection === 'sold'
+ ? 'sold'
+ : rejection === 'deleted'
+ ? 'withdrawn'
+ : 'unobserved'
+ );
+ await expect(
+ panel(page).getByRole('button', { name: 'Message seller', exact: true })
+ ).toHaveCount(0);
expect(await page.evaluate(() => window.hcp106Fixture.capture())).toBe(
false
);
diff --git a/web/tests/e2e/product-request.spec.ts b/web/tests/e2e/product-request.spec.ts
@@ -17,6 +17,18 @@ declare global {
let server: Awaited<ReturnType<typeof createStaticHarness>>;
let sockets: WebSocketServer, endpoint: string, bundle: string;
let missingOwn = false;
+let listingStatus: 'active' | 'sold' | 'withdrawn' = 'active';
+let sellerInbox:
+ | 'normal'
+ | 'missing'
+ | 'unsupported'
+ | 'unapproved'
+ | 'malformed'
+ | 'partial' = 'normal';
+let incompleteListing = false;
+let holdListingHead = false;
+let headUpdates: (() => void)[] = [],
+ deletionUpdates: (() => void)[] = [];
let holdOwnEose = false,
holdPeerEose = false;
let waitingEose: (() => void)[] = [];
@@ -97,20 +109,94 @@ test.beforeAll(async () => {
['location', 'Victoria'],
['price', '3.5', 'CAD'],
['radroots:price_unit', 'lb'],
- ['status', 'active']
+ ['status', listingStatus === 'sold' ? 'sold' : 'active']
]
},
sellerSecret
);
socket.send(JSON.stringify(['EVENT', frame[1], event]));
+ headUpdates.push(() => {
+ if (socket.readyState === 1)
+ socket.send(
+ JSON.stringify([
+ 'EVENT',
+ frame[1],
+ finalizeEvent(
+ {
+ ...event,
+ created_at: 1700000080,
+ tags: event.tags.map((tag) =>
+ tag[0] === 'status'
+ ? [
+ 'status',
+ listingStatus === 'sold' ? 'sold' : 'active'
+ ]
+ : tag
+ )
+ },
+ sellerSecret
+ )
+ ])
+ );
+ });
}
+ if (filter.kinds?.includes(5))
+ deletionUpdates.push(() => {
+ if (socket.readyState === 1)
+ socket.send(
+ JSON.stringify([
+ 'EVENT',
+ frame[1],
+ finalizeEvent(
+ {
+ kind: 5,
+ created_at: 1700000090,
+ tags: [['a', '30402:' + peer + ':carrots']],
+ content: ''
+ },
+ sellerSecret
+ )
+ ])
+ );
+ });
+ if (filter.kinds?.includes(5) && listingStatus === 'withdrawn')
+ socket.send(
+ JSON.stringify([
+ 'EVENT',
+ frame[1],
+ finalizeEvent(
+ {
+ kind: 5,
+ created_at: 1700000070,
+ tags: [['a', '30402:' + peer + ':carrots']],
+ content: ''
+ },
+ sellerSecret
+ )
+ ])
+ );
if (filter.kinds?.includes(10050)) {
- if (filter.authors?.includes(peer))
+ if (filter.authors?.includes(peer) && sellerInbox !== 'missing')
socket.send(
JSON.stringify([
'EVENT',
frame[1],
- preference(sellerSecret, 'wss://peer.example.org')
+ sellerInbox === 'normal' || sellerInbox === 'partial'
+ ? preference(sellerSecret, 'wss://peer.example.org')
+ : finalizeEvent(
+ {
+ kind: 10050,
+ created_at: 1700000060,
+ content: '',
+ tags:
+ sellerInbox === 'unapproved'
+ ? [['relay', 'wss://unapproved.example.org']]
+ : sellerInbox === 'unsupported'
+ ? [['relay', 'https://unsupported.example.org']]
+ : [['relay']]
+ },
+ sellerSecret
+ )
])
);
if (filter.authors?.includes(owner) && (!missingOwn || ownPreference))
@@ -125,11 +211,16 @@ test.beforeAll(async () => {
}
}
if (
+ (holdListingHead &&
+ filters.some((filter) => filter.kinds?.includes(30402))) ||
+ (incompleteListing &&
+ filters.some((filter) => filter.kinds?.includes(5))) ||
filters.some(
(filter) =>
filter.kinds?.includes(10050) &&
((holdOwnEose && filter.authors?.includes(owner)) ||
- (holdPeerEose && filter.authors?.includes(peer)))
+ ((holdPeerEose || sellerInbox === 'partial') &&
+ filter.authors?.includes(peer)))
)
)
waitingEose.push(() => {
@@ -177,6 +268,12 @@ test.afterAll(async () => {
test.beforeEach(async ({ page }) => {
events = [];
missingOwn = false;
+ listingStatus = 'active';
+ sellerInbox = 'normal';
+ incompleteListing = false;
+ holdListingHead = false;
+ headUpdates = [];
+ deletionUpdates = [];
ownPreference = undefined;
holdOwnEose = false;
holdPeerEose = false;
@@ -211,6 +308,150 @@ test.afterEach(async ({ page }) => {
const panel = (page: Page) => page.locator('[data-request-fixture]');
const editor = (page: Page) =>
panel(page).getByRole('textbox', { name: 'Your message', exact: true });
+for (const status of ['sold', 'withdrawn'] as const)
+ test(`HCP108 known ${status} food has no new enquiry and remains readable`, async ({
+ page
+ }) => {
+ listingStatus = status;
+ await page.evaluate(async () => {
+ window.hcp107Fixture = await window.hcp107.renderFixture();
+ });
+ await expect
+ .poll(() =>
+ page.evaluate(() => window.hcp107Fixture.viewSnapshot().outcome)
+ )
+ .toBe(status);
+ await expect(
+ panel(page).getByRole('button', { name: 'Message seller', exact: true })
+ ).toHaveCount(0);
+ expect(
+ await page.evaluate(
+ () => window.hcp107Fixture.viewSnapshot().reference.pubkey
+ )
+ ).toBe(peer);
+ expect(
+ await page.evaluate(() => window.hcp107Fixture.message())
+ ).toBeUndefined();
+ await noPrivate(page);
+ });
+
+test('HCP108 incomplete active terms need explicit original acknowledgement and retain signed citations', async ({
+ page
+}) => {
+ incompleteListing = true;
+ await page.evaluate(async () => {
+ window.hcp107Fixture = await window.hcp107.renderFixture();
+ });
+ await expect
+ .poll(() =>
+ page.evaluate(() => window.hcp107Fixture.viewSnapshot().outcome)
+ )
+ .toBe('active');
+ await expect(
+ panel(page).getByRole('button', { name: 'Message seller', exact: true })
+ ).toBeDisabled();
+ expect(
+ await page.evaluate(() => window.hcp107Fixture.captureUncertain(undefined))
+ ).toBe(false);
+ await panel(page)
+ .getByRole('button', {
+ name: 'I understand the listing status is uncertain',
+ exact: true
+ })
+ .click();
+ await panel(page)
+ .getByRole('button', { name: 'Message seller', exact: true })
+ .click();
+ await expect(editor(page)).toBeVisible();
+ const observed = await page.evaluate(() => ({
+ product: window.hcp107Fixture.product(),
+ view: window.hcp107Fixture.viewSnapshot(),
+ message: window.hcp107Fixture.message()
+ }));
+ expect(observed.product?.eventId).toBe(observed.view.eventId);
+ expect(observed.message?.tags).toEqual([['p', peer]]);
+ expect(observed.message?.content).toContain(
+ 'nostr:' + observed.product?.nevent
+ );
+ await noPrivate(page);
+ await unlock(page);
+ await panel(page)
+ .getByRole('button', { name: 'Send request', exact: true })
+ .click();
+ await expect
+ .poll(() => events.filter((row) => row.event.kind === 1059).length)
+ .toBe(2);
+ expect(
+ events
+ .filter((row) => row.event.kind === 1059)
+ .map((row) => row.origin)
+ .sort()
+ ).toEqual(['wss://archive.example.org', 'wss://peer.example.org']);
+ await expect
+ .poll(() => page.evaluate(() => window.hcp107Fixture.snapshot()?.state))
+ .toBe('completed');
+});
+
+test('HCP108 connecting as the verified publisher shows Manage and keeps unsent memory without self enquiry', async ({
+ page
+}) => {
+ await ready(page);
+ await editor(page).fill(
+ 'Keep this guest text after discovering my own listing'
+ );
+ await page.evaluate(() => window.hcp107Fixture.mode('changed_key'));
+ await panel(page)
+ .getByRole('button', { name: 'Connect extension', exact: true })
+ .click();
+ await expect(
+ panel(page).getByRole('link', { name: 'Manage listing', exact: true })
+ ).toBeVisible();
+ await expect(
+ panel(page).getByRole('button', { name: 'Send request', exact: true })
+ ).toBeDisabled();
+ await expect(editor(page)).toHaveValue(
+ 'Keep this guest text after discovering my own listing'
+ );
+ await noPrivate(page);
+});
+
+for (const status of [
+ 'missing',
+ 'unsupported',
+ 'malformed',
+ 'partial'
+] as const)
+ test(`HCP108 ${status} seller inbox cannot guess a send destination`, async ({
+ page
+ }) => {
+ sellerInbox = status;
+ await ready(page);
+ await unlock(page);
+ await panel(page)
+ .getByRole('button', { name: 'Send request', exact: true })
+ .click();
+ if (status === 'partial') {
+ await expect
+ .poll(() => page.evaluate(() => window.hcp107Fixture.snapshot()?.state))
+ .toBe('checking');
+ await page.evaluate(() => window.hcp107Fixture.advance());
+ }
+ await expect(panel(page)).toContainText(
+ status === 'missing'
+ ? 'In-app messaging is not available for this seller in this prototype.'
+ : status === 'unsupported' || status === 'malformed'
+ ? 'The seller inbox configuration is unsupported in this prototype.'
+ : 'The seller inbox could not be confirmed from the sources checked.'
+ );
+ await expect(
+ panel(page).getByRole('button', { name: 'Send request', exact: true })
+ ).toBeDisabled();
+ await expect(editor(page)).toBeVisible();
+ expect(
+ await page.evaluate(() => window.hcp107Fixture.viewSnapshot().food?.title)
+ ).toBe('Verified carrots');
+ await noPrivate(page);
+ });
async function ready(page: Page, qualified = true) {
await page.evaluate(async (qualified) => {
window.hcp107Fixture = await window.hcp107.renderFixture(qualified);
@@ -225,6 +466,201 @@ async function ready(page: Page, qualified = true) {
.click();
await expect(editor(page)).toBeVisible();
}
+test('HCP108 a signed but unapproved seller inbox is unavailable without guessed routing', async ({
+ page
+}) => {
+ sellerInbox = 'unapproved';
+ await ready(page);
+ await unlock(page);
+ await panel(page)
+ .getByRole('button', { name: 'Send request', exact: true })
+ .click();
+ await expect
+ .poll(() => page.evaluate(() => window.hcp107Fixture.snapshot()?.state))
+ .toBe('needs_action');
+ expect(
+ await page.evaluate(() => window.hcp107Fixture.snapshot()?.copy)
+ ).toContain(
+ 'The seller inbox configuration is unsupported in this prototype.'
+ );
+ await noPrivate(page);
+});
+async function uncertain(page: Page) {
+ incompleteListing = true;
+ holdListingHead = true;
+ await page.evaluate(async () => {
+ window.hcp107Fixture = await window.hcp107.renderFixture();
+ });
+ await expect
+ .poll(() =>
+ page.evaluate(() => window.hcp107Fixture.viewSnapshot().outcome)
+ )
+ .toBe('active');
+ await panel(page)
+ .getByRole('button', {
+ name: 'I understand the listing status is uncertain',
+ exact: true
+ })
+ .click();
+ await panel(page)
+ .getByRole('button', { name: 'Message seller', exact: true })
+ .click();
+ await expect(editor(page)).toBeVisible();
+}
+test('HCP108 copied consent and genuine consent from another original view cannot acknowledge uncertain terms', async ({
+ page
+}) => {
+ await uncertain(page);
+ await page.evaluate(() => window.hcp107Fixture.createOtherView());
+ await expect
+ .poll(() =>
+ page.evaluate(() => window.hcp107Fixture.otherViewSnapshot()?.outcome)
+ )
+ .toBe('active');
+ expect(
+ await page.evaluate(() => window.hcp107Fixture.consentCases())
+ ).toEqual({
+ genuine: true,
+ current: true,
+ copied: false,
+ other: false,
+ otherControl: true,
+ unreviewed: false
+ });
+ await noPrivate(page);
+});
+for (const change of ['coverage', 'close'] as const)
+ test(`HCP108 original ${change} transition revokes genuine uncertainty consent`, async ({
+ page
+ }) => {
+ await uncertain(page);
+ expect(
+ (await page.evaluate(() => window.hcp107Fixture.consentCases())).current
+ ).toBe(true);
+ await editor(page).fill('uncertainty-memory-marker');
+ if (change === 'coverage')
+ await page.evaluate(() => window.hcp107Fixture.advance());
+ else await page.evaluate(() => window.hcp107Fixture.closeView());
+ expect(
+ await page.evaluate(() => window.hcp107Fixture.consentCurrent())
+ ).toBe(false);
+ expect(
+ await page.evaluate(() => window.hcp107Fixture.message())
+ ).toBeUndefined();
+ if (change === 'coverage')
+ expect(
+ await page.evaluate(() => window.hcp107Fixture.product()?.text)
+ ).toBe('uncertainty-memory-marker');
+ else
+ expect(
+ await page.evaluate(() => window.hcp107Fixture.product())
+ ).toBeUndefined();
+ await noPrivate(page);
+ });
+for (const change of ['sold', 'withdrawn', 'version'] as const)
+ test(`HCP108 a real newer ${change} observation revokes request consent while preserving unsent text`, async ({
+ page
+ }) => {
+ await uncertain(page);
+ expect(
+ (await page.evaluate(() => window.hcp107Fixture.consentCases())).current
+ ).toBe(true);
+ await editor(page).fill('changed-listing-memory-marker');
+ const before = await page.evaluate(
+ () => window.hcp107Fixture.product()?.eventId
+ );
+ if (change === 'withdrawn') {
+ listingStatus = 'withdrawn';
+ for (const update of deletionUpdates) update();
+ } else {
+ listingStatus = change === 'sold' ? 'sold' : 'active';
+ for (const update of headUpdates) update();
+ }
+ if (change === 'version')
+ await expect
+ .poll(() =>
+ page.evaluate(() => window.hcp107Fixture.viewSnapshot().eventId)
+ )
+ .not.toBe(before);
+ else
+ await expect
+ .poll(() =>
+ page.evaluate(() => window.hcp107Fixture.viewSnapshot().outcome)
+ )
+ .toBe(change);
+ expect(
+ await page.evaluate(() => window.hcp107Fixture.consentCurrent())
+ ).toBe(false);
+ expect(
+ await page.evaluate(() => window.hcp107Fixture.product()?.text)
+ ).toBe('changed-listing-memory-marker');
+ expect(
+ await page.evaluate(() => window.hcp107Fixture.message())
+ ).toBeUndefined();
+ await expect(
+ panel(page).getByRole('button', { name: 'Send request', exact: true })
+ ).toBeDisabled();
+ await noPrivate(page);
+ });
+for (const change of ['cancel', 'account'] as const)
+ test(`HCP108 retired peer lookup cannot replace newer ${change} state`, async ({
+ page
+ }) => {
+ await ready(page);
+ await unlock(page);
+ holdPeerEose = true;
+ await panel(page)
+ .getByRole('button', { name: 'Send request', exact: true })
+ .click();
+ await expect.poll(() => waitingEose.length).toBeGreaterThan(0);
+ if (change === 'cancel') {
+ await panel(page)
+ .getByRole('button', { name: 'Cancel', exact: true })
+ .click();
+ await panel(page)
+ .getByRole('button', { name: 'Keep editing', exact: true })
+ .click();
+ } else await page.evaluate(() => window.hcp107Fixture.logout());
+ holdPeerEose = false;
+ for (const release of waitingEose) release();
+ await expect
+ .poll(() => page.evaluate(() => window.hcp107Fixture.snapshot()?.busy))
+ .toBe(false);
+ expect(
+ await page.evaluate(() => window.hcp107Fixture.snapshot()?.copy)
+ ).toContain(
+ change === 'cancel' ? 'Sending is paused.' : 'Connection changed.'
+ );
+ await noPrivate(page);
+ });
+for (const change of ['sold', 'withdrawn', 'version'] as const)
+ test(`HCP108 ${change} during peer lookup reports listing review without relabelling a seller inbox failure`, async ({
+ page
+ }) => {
+ await uncertain(page);
+ await unlock(page);
+ holdPeerEose = true;
+ await panel(page)
+ .getByRole('button', { name: 'Send request', exact: true })
+ .click();
+ await expect
+ .poll(() => page.evaluate(() => window.hcp107Fixture.snapshot()?.state))
+ .toBe('checking');
+ if (change === 'withdrawn') {
+ listingStatus = 'withdrawn';
+ for (const update of deletionUpdates) update();
+ } else {
+ listingStatus = change === 'sold' ? 'sold' : 'active';
+ for (const update of headUpdates) update();
+ }
+ await expect
+ .poll(() => page.evaluate(() => window.hcp107Fixture.snapshot()?.busy))
+ .toBe(false);
+ expect(
+ await page.evaluate(() => window.hcp107Fixture.snapshot()?.copy)
+ ).toContain('Review the current listing before sending.');
+ await noPrivate(page);
+ });
async function connect(page: Page) {
await panel(page)
.getByRole('button', { name: 'Connect extension', exact: true })
diff --git a/web/tests/provenance/output.test.mjs b/web/tests/provenance/output.test.mjs
@@ -1098,6 +1098,7 @@ import { auditOutput } from '../../tools/check-output.mjs';
'src/lib/components/ProductEnquiry.svelte',
'src/lib/messaging/product-enquiry.ts',
'src/lib/messaging/product-request-controller.ts',
+ 'src/lib/messaging/enquiry-readiness.ts',
'src/lib/messaging/resolve-inbox.ts',
'src/lib/components/CapabilityGate.svelte',
'src/lib/messaging/enquiry-context.ts',
diff --git a/web/tests/unit/enquiry-readiness.test.ts b/web/tests/unit/enquiry-readiness.test.ts
@@ -0,0 +1,39 @@
+import { describe, expect, it } from 'vitest';
+import {
+ acknowledgeProductViewUncertainty,
+ productViewListingOwnership,
+ type ProductView,
+ type ProductStatusAcknowledgement
+} from '../../src/lib/catalog/product-view.ts';
+import { enquiryReadinessSnapshot } from '../../src/lib/messaging/enquiry-readiness.ts';
+import type { IdentitySession } from '../../src/lib/runtime/identity-session.ts';
+import type { InboxResolver } from '../../src/lib/messaging/resolve-inbox.ts';
+
+describe('enquiry availability uses original evidence owners', () => {
+ it('copied view and a review string cannot acknowledge last-known status', () => {
+ expect(
+ acknowledgeProductViewUncertainty(
+ {} as ProductView,
+ 'reviewed_last_known_listing'
+ )
+ ).toBeUndefined();
+ });
+ it('a copied acknowledgement cannot manufacture a listing witness', () => {
+ expect(
+ productViewListingOwnership(
+ {} as ProductView,
+ {} as ProductStatusAcknowledgement
+ )
+ ).toBeUndefined();
+ });
+ it('displayed identity, food and inbox copies cannot create readiness', () => {
+ expect(
+ enquiryReadinessSnapshot(
+ {} as ProductView,
+ {} as IdentitySession,
+ {} as ProductStatusAcknowledgement,
+ {} as InboxResolver
+ )
+ ).toMatchObject({ action: 'unavailable', sellerInbox: 'unchecked' });
+ });
+});
diff --git a/web/tools/check-output.mjs b/web/tools/check-output.mjs
@@ -412,9 +412,9 @@ async function productPresentationAdmission(web) {
const producers = hasRequest
? {
'src/routes/products/[naddr=naddr]/+page.svelte':
- '970f716e5f31bb0a7e463db84876d4f4b0801979e0893ef69fbeed1b17d69b0f',
+ 'e63a2c8b3833966a36e4d97aef7726ff3d087703cc9b475e7f52f5478fed5ce7',
'src/lib/catalog/product-view.ts':
- 'e608bcc5b7918366e2daabd5f5270cabf0ded22e1bbfd413d26450387ebac171',
+ 'c2562d1470282c758889e9855f7e7e6c32a6b2eb090e4dace2e94fdfdb6d8363',
'src/lib/components/ListingFacts.svelte':
'65d009b4940e7ced61347919689877da9473a2a66a44f61cc5e7bd0b2d217215',
'src/lib/components/PublisherIdentity.svelte':
@@ -430,17 +430,19 @@ async function productPresentationAdmission(web) {
'src/lib/catalog/resolve-head.ts':
'4f1c9f144164580da038d127ab463f9f8ba6b20e882fc31151cb29850782d633',
'src/lib/components/ProductEnquiry.svelte':
- 'a13db6509100a0db73536211301b22cb42e86b3c2ad06d861f61a679ae6ac635',
+ 'b49f555a239ab31253f403cc98eaf82413b2584c71e336262202fe840b9227a2',
'src/lib/messaging/product-enquiry.ts':
- '093fe1d5331b81fcf63efeae2b17e5f2c39cbab990e542a13e529a39e28eb8f1',
+ '6652f4af6b45ae14d82bf4d6b56dea7e95af8b254d9b41da9528cf34e87d2052',
'src/lib/messaging/enquiry-context.ts':
'fc00bb77f601427fb73defc0c758332c3465c2d583bfa1f7b996f808f508b735',
'src/lib/messaging/product-request-controller.ts':
- 'd26242d348c6575cfae197833f3cf5a12751cf987c0f36322a647cc55e2bcb22',
+ '9fb8bb41657de661d4fe32d05f78fdc453e215467b08ee7d8036d39093cb0979',
'src/lib/components/CapabilityGate.svelte':
'38584846f67135d03ad531199cfd4e5f9dbcede58ca7baa2ee2d14fd9f46d414',
'src/lib/messaging/resolve-inbox.ts':
- '6c6438c518f13916a4a5664d8dd0e313338219bd52d5a91db8abab9bbc4a794c'
+ '6c6438c518f13916a4a5664d8dd0e313338219bd52d5a91db8abab9bbc4a794c',
+ 'src/lib/messaging/enquiry-readiness.ts':
+ '8c7a526c763d43c0ef04aec8ae00dd5d6858911d9c5a18a87127100c5b57782a'
}
: hasEnquiry
? {