feat(approvals,audit): record the reviewer as the unchecked claim it is

The hub copies the reviewer string a client sends straight into
decided_by (DecideApproval, ClearEventLog); nothing on the wire ties
it to the authenticated caller. Studio filled it from the OS account,
so an export read like non-repudiation while being an arbitrary
client claim — the legal finding of the 2026-07-26 usertest panel.

The real fix is hub-side (derive decided_by from CALLER_IDENTITY);
that contract is written down in docs/reviewer-identity.md and needs
a hub release. Until then Studio does the one thing it can do
honestly and marks its own claim as a claim, inside the record:

- data/reviewer_identity.dart is the single place that produces and
  reads the value; wire() is idempotent, so page and HubService may
  both normalise. Every write path funnels through HubService, so no
  surface can send a bare handle.
- The inbox states before the decision who will be recorded, what
  that attribution is worth on this hub (from AuthStatus), and the
  literal string that lands in decided_by. An unreadable auth policy
  stays unreadable — never optimistic.
- Reading back: a marked value shows its plain name plus an
  unchecked flag; an unmarked one (legacy row, CLI decision, or a
  future hub-derived identity) is not classified either way.
- The audit wipe seeds the same kind of marked attribution into its
  chain.reset marker.

When the hub starts deriving the value it overwrites the field and
the prefix disappears by itself — no Studio release needed.

Guards: reviewer_identity_test (the value) and
approvals_reviewer_identity_test (every surface that writes or
renders it, against the hermetic fake hub). Visual proof for both
themes via the dialog-shot harness.

Signed-off-by: flemming-it <stefan.a.flemming@googlemail.com>
This commit is contained in:
flemming-it 2026-08-03 23:50:34 +02:00
parent 415f8a7ddb
commit ebc668d28d
15 changed files with 1129 additions and 41 deletions

View file

@ -16,6 +16,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import '../l10n/app_localizations.dart';
import 'flow_output.dart';
import 'hub_auth_token.dart';
import 'reviewer_identity.dart';
export 'flow_output.dart';
class HubService {
@ -649,12 +650,18 @@ class HubService {
/// `production`; the gRPC error surfaces as an exception so
/// the caller can show the operator why it was blocked.
/// Returns `(purged, channel)` so the UI can confirm what
/// just happened.
/// just happened. [reviewer] is the operator's typed handle and
/// goes out through [ReviewerIdentity.wire] for the same reason
/// approvals do: the marker the hub seeds is read by auditors and
/// must not claim a verified identity Studio cannot supply.
Future<({int purged, String channel})> clearEventLog({
required String reviewer,
required String reason,
}) async {
final r = await _client.clearEventLog(reviewer: reviewer, reason: reason);
final r = await _client.clearEventLog(
reviewer: ReviewerIdentity.wire(reviewer),
reason: reason,
);
return (purged: r.purged.toInt(), channel: r.channel);
}
@ -1175,11 +1182,22 @@ class HubService {
.toList();
}
/// Decide an approval. [reviewer] is the operator-facing handle;
/// it leaves Studio through [ReviewerIdentity.wire], which labels
/// it as the unchecked client claim it is the hub stores the
/// string verbatim, so the record has to carry its own trust
/// level (see `lib/data/reviewer_identity.dart`). Every decide
/// path (approvals page, batch actions, the flow-editor run
/// driver) funnels through here so none of them can bypass that.
Future<void> approve(String id, String reviewer) =>
_client.approve(approvalId: id, reviewer: reviewer);
_client.approve(approvalId: id, reviewer: ReviewerIdentity.wire(reviewer));
Future<void> reject(String id, String reviewer, String reason) =>
_client.reject(approvalId: id, reviewer: reviewer, reason: reason);
Future<void> reject(String id, String reviewer, String reason) => _client
.reject(
approvalId: id,
reviewer: ReviewerIdentity.wire(reviewer),
reason: reason,
);
/// Detached-runs monitor snapshot: every tracked invocation
/// (newest-first, optionally scoped to one [project]) plus whether