feat: enable creator notification command
CI / test (pull_request) Successful in 11s
CI / test (push) Successful in 11s

This commit was merged in pull request #10.
This commit is contained in:
m
2026-08-16 19:19:00 +03:00
parent 6e0040fe89
commit c6139699a9
16 changed files with 622 additions and 18 deletions
+2
View File
@@ -159,6 +159,8 @@ func creatorRoute(method, path string) (routeTarget, string, bool) {
return targetCommit, "/v1/creator/authorized-actions", true
case method == http.MethodPost && path == "/api/actions/satisfy-delivered":
return targetCommit, "/v1/creator/continuity/satisfy-delivered", true
case method == http.MethodPost && path == "/api/actions/notify-delivered":
return targetCommit, "/v1/creator/continuity/notify-delivered", true
case method == http.MethodPost && strings.HasPrefix(path, "/api/actions/") && strings.HasSuffix(path, "/reconcile"):
id := strings.TrimSuffix(strings.TrimPrefix(path, "/api/actions/"), "/reconcile")
if validID(id) {
+29
View File
@@ -74,6 +74,7 @@ func TestGatewayDeniesInternalAndMutationRoutes(t *testing.T) {
{http.MethodGet, "/api/tasks/../../healthz"},
{http.MethodPost, "/api/actions/arbitrary"},
{http.MethodGet, "/api/actions/satisfy-delivered"},
{http.MethodGet, "/api/actions/notify-delivered"},
} {
request := httptest.NewRequest(test.method, test.path, nil)
response := httptest.NewRecorder()
@@ -158,6 +159,34 @@ func TestGatewayRoutesOnlyBoundedCreatorCommandsToCommit(t *testing.T) {
}
}
func TestGatewayRoutesTypedNotificationCommandToCommit(t *testing.T) {
commitRuntime := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v1/creator/continuity/notify-delivered" || r.Method != http.MethodPost {
t.Fatalf("unexpected Commit target %s %s", r.Method, r.URL.Path)
}
body, _ := io.ReadAll(r.Body)
text := string(body)
if !strings.Contains(text, "prospective-1") || !strings.Contains(text, "Confirm") || strings.Contains(text, "URL") || strings.Contains(text, "CapabilityID") {
t.Fatalf("unexpected notification body %s", text)
}
w.WriteHeader(http.StatusCreated)
_, _ = io.WriteString(w, `{"State":"SUCCEEDED"}`)
}))
defer commitRuntime.Close()
handler, err := newHandler("http://core-runtime.invalid", "http://continuity-runtime.invalid", commitRuntime.URL, commitRuntime.Client())
if err != nil {
t.Fatal(err)
}
request := httptest.NewRequest(http.MethodPost, "/api/actions/notify-delivered", strings.NewReader(`{"ProspectiveItemID":"prospective-1","Confirm":true}`))
request.Header.Set("Authorization", "Bearer bounded-session")
request.Header.Set("Content-Type", "application/json")
response := httptest.NewRecorder()
handler.ServeHTTP(response, request)
if response.Code != http.StatusCreated {
t.Fatalf("response=%d %s", response.Code, response.Body.String())
}
}
func TestGatewayRoutesCreatorActionHistoryToCommit(t *testing.T) {
commitRuntime := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v1/creator/authorized-actions" || r.URL.RawQuery != "limit=25" || r.Method != http.MethodGet {
@@ -198,6 +198,11 @@ button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px
.action-result strong[data-state="FAILED"] { color: var(--bad); }
.action-result strong[data-state="UNKNOWN_OUTCOME"] { color: var(--warn); }
.action-result .secondary-button { min-width: 154px; margin: 0; padding: 0 14px; }
.notification-command { grid-column: 1 / -1; padding: 14px 0 0; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-top: 1px solid var(--line-soft); }
.notification-command div { min-width: 0; }
.notification-command strong { display: block; margin-bottom: 5px; color: var(--ink); font: 600 10px/1.2 var(--mono); letter-spacing: .06em; text-transform: uppercase; }
.notification-command span { display: block; color: var(--muted); font-size: 11px; line-height: 1.45; }
.notification-command .secondary-button { flex: 0 0 auto; min-width: 190px; margin: 0; }
.confirmation-dialog { width: min(560px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); background: #111915; box-shadow: var(--shadow); }
.confirmation-dialog::backdrop { background: rgba(3, 6, 5, .78); backdrop-filter: blur(5px); }
.confirmation-dialog form { padding: 30px; }
@@ -269,6 +274,8 @@ button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px
.commit-zone-copy { grid-column: auto; grid-row: auto; margin-bottom: 6px; }
.action-result { grid-template-columns: 1fr; align-items: stretch; }
.action-result .secondary-button { width: 100%; }
.notification-command { align-items: stretch; flex-direction: column; }
.notification-command .secondary-button { width: 100%; }
.confirmation-dialog form { padding: 24px 20px; }
.confirmation-grid { grid-template-columns: 1fr; }
.confirmation-grid .wide { grid-column: auto; }
+63
View File
@@ -11,6 +11,7 @@ let toastTimer;
let currentTask = null;
let currentProspective = null;
let pendingCommand = null;
let pendingNotification = null;
let lastAuthorizedActionID = "";
function setText(id, value, fallback = "—") {
@@ -93,6 +94,7 @@ function endSession(message = "Сессия завершена.") {
currentTask = null;
currentProspective = null;
pendingCommand = null;
pendingNotification = null;
lastAuthorizedActionID = "";
notify(message);
}
@@ -426,6 +428,7 @@ async function loadCapability(capabilityID) {
function updateActionReadiness() {
const button = byId("prepare-satisfaction");
const notificationButton = byId("prepare-notification");
if (!button) return;
const evidence = byId("satisfaction-evidence").value.trim();
let message = "Доступно только для доставленного ожидания с проверенной Work-задачей.";
@@ -441,6 +444,19 @@ function updateActionReadiness() {
}
button.disabled = !ready;
setText("action-readiness", message);
let notificationReady = false;
let notificationMessage = "Доступно для доставленного ожидания с проверенной Work-задачей.";
if (!currentProspective) notificationMessage = "Сначала выберите и загрузите ожидание.";
else if (currentProspective.State !== "DELIVERED") notificationMessage = `Состояние ${currentProspective.State || "UNKNOWN"}: уведомление доступно только для DELIVERED.`;
else if (!currentTask) notificationMessage = "Загрузите проверенную Work-задачу как обоснование.";
else if (currentTask.GoalID !== currentProspective.GoalID || currentTask.ScopeID !== currentProspective.ScopeID) notificationMessage = "Цель или область Work-задачи не совпадает с ожиданием.";
else {
notificationReady = true;
notificationMessage = `Готово: receiver получит фиксированный шаблон для ${currentProspective.ID} · rev ${currentProspective.Revision}.`;
}
notificationButton.disabled = !notificationReady;
setText("notification-readiness", notificationMessage);
}
byId("satisfaction-evidence").addEventListener("input", updateActionReadiness);
@@ -473,6 +489,53 @@ byId("cancel-satisfaction").addEventListener("click", () => {
byId("satisfaction-dialog").close();
});
byId("prepare-notification").addEventListener("click", () => {
updateActionReadiness();
if (byId("prepare-notification").disabled || !currentTask || !currentProspective) return;
pendingNotification = {
Target: {TaskID: currentTask.TaskID, GoalID: currentTask.GoalID, ScopeID: currentTask.ScopeID, Revision: currentTask.Revision},
ProspectiveItemID: currentProspective.ID,
ExpectedRevision: currentProspective.Revision,
Confirm: true,
};
setText("notify-confirm-prospective", pendingNotification.ProspectiveItemID);
setText("notify-confirm-prospective-revision", pendingNotification.ExpectedRevision);
setText("notify-confirm-task", pendingNotification.Target.TaskID);
setText("notify-confirm-task-revision", pendingNotification.Target.Revision);
setText("notification-confirmation-error", "", "");
byId("notification-dialog").showModal();
});
byId("cancel-notification").addEventListener("click", () => {
pendingNotification = null;
byId("notification-dialog").close();
});
byId("confirm-notification").addEventListener("click", async () => {
if (!pendingNotification) return;
const command = pendingNotification;
const button = byId("confirm-notification");
const prepare = byId("prepare-notification");
button.disabled = true;
prepare.disabled = true;
button.textContent = "Отправляю…";
setText("notification-confirmation-error", "", "");
try {
const result = await request("/api/actions/notify-delivered", {method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify(command)});
pendingNotification = null;
byId("notification-dialog").close();
renderActionResult(result);
await loadActionHistory();
notify(result.State === "SUCCEEDED" ? "Receiver принял уведомление." : "Исход отправки требует сверки.");
} catch (error) {
setText("notification-confirmation-error", error.message);
} finally {
button.disabled = false;
button.textContent = "Подтверждаю отправку";
updateActionReadiness();
}
});
byId("confirm-satisfaction").addEventListener("click", async () => {
if (!pendingCommand) return;
const command = pendingCommand;
+24
View File
@@ -164,6 +164,10 @@
<button id="prepare-satisfaction" class="commit-button" type="button" disabled>
<span>Отметить исполненным</span><span aria-hidden="true">→</span>
</button>
<div class="notification-command">
<div><strong>Windows-напоминание</strong><span id="notification-readiness">Доступно для доставленного ожидания с проверенной Work-задачей.</span></div>
<button id="prepare-notification" class="secondary-button" type="button" disabled>Отправить уведомление</button>
</div>
<div id="action-result" class="action-result" hidden>
<div><span>ИСХОД</span><strong id="action-state">—</strong></div>
<div><span>ACTION</span><code id="action-id">—</code></div>
@@ -209,6 +213,26 @@
</form>
</dialog>
<dialog id="notification-dialog" class="confirmation-dialog" aria-labelledby="notification-confirmation-title">
<form method="dialog">
<p class="eyebrow">commit / внешнее действие</p>
<h2 id="notification-confirmation-title">Отправить напоминание?</h2>
<p class="confirmation-copy">Домовой создаст неизменяемое авторизованное действие и передаст типизированное уведомление в закреплённый receiver. Состояние Continuity не изменится; доставка не означает прочтение.</p>
<dl class="confirmation-grid">
<div><dt>Ожидание</dt><dd id="notify-confirm-prospective">—</dd></div>
<div><dt>Ревизия</dt><dd id="notify-confirm-prospective-revision">—</dd></div>
<div><dt>Work-задача</dt><dd id="notify-confirm-task">—</dd></div>
<div><dt>Ревизия Work</dt><dd id="notify-confirm-task-revision">—</dd></div>
<div class="wide"><dt>Канал</dt><dd>Локальное уведомление Windows · закреплённый receiver</dd></div>
</dl>
<p id="notification-confirmation-error" class="form-error" role="alert"></p>
<div class="confirmation-actions">
<button id="cancel-notification" class="text-button" type="button">Отмена</button>
<button id="confirm-notification" class="commit-button" type="button">Подтверждаю отправку</button>
</div>
</form>
</dialog>
<div id="toast" class="toast" role="status" aria-live="polite" hidden></div>
<script src="/assets/console.js" defer></script>
</body>