proto: land F2 — download.provideAuth (1.2.0)
The last contract gap blocking an M1 definition-of-done item: CORE's "401
handled" has no return path without it, and B2a's sibling F2 was accepted in
proto-answers-m1.md but never actually landed.
download.provideAuth {taskId, username, password, save?} -> {ok}, exactly as
proposed there. Privileged and Unix-socket-only: a credential-bearing method
must never be reachable from the browser, which is the other half of the
promise event.auth.required's own description already makes ("never back
through this event, never into a log"). It answers the challenge; it does not
itself resume the task -- the daemon retries with the credential attached and
the ordinary event.task.state reports the task leaving retry_wait, the same
as any other state change.
save only tells the daemon whether to persist the credential in the Secret
Service for next time, or use it for this attempt alone -- it never touches
SQLite or a log either way, in keeping with CLAUDE.md's secrets rule.
Three fixtures: the success path, -32010 for a task that no longer exists
(credentials submitted for it are simply discarded), and -32003 confirming
the extension has no path to this method under any transport.
mockd gets a real handler rather than falling through to the generic fixture
responder: it validates the taskId exists (so the -32010 fixture is
replayable) and actually transitions the task out of retry_wait.
Minor bump, 1.1.0 -> 1.2.0: additive method, no existing type touched.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012fgjnqFCS5h5L7gZTZo3rV
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
//
|
||||
// Source: contracts/schema/**
|
||||
// Generator: contracts/codegen/gen_cpp.py
|
||||
// Contract: v1.1.0
|
||||
// Contract: v1.2.0
|
||||
//
|
||||
// Hand-editing this file is a merge blocker. Fix the schema and regenerate:
|
||||
// python3 contracts/codegen/gen_cpp.py
|
||||
@@ -4369,6 +4369,78 @@ template <> Result<DownloadProbeResult> parse<DownloadProbeResult>(const nlohman
|
||||
return out;
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& j, const DownloadProvideAuthParams& v) {
|
||||
j = nlohmann::json::object();
|
||||
j["taskId"] = v.taskId;
|
||||
j["username"] = v.username;
|
||||
j["password"] = v.password;
|
||||
if (v.save.has_value()) j["save"] = *v.save;
|
||||
}
|
||||
|
||||
template <> Result<DownloadProvideAuthParams> parse<DownloadProvideAuthParams>(const nlohmann::json& j, std::string_view path) {
|
||||
if (!j.is_object()) return std::unexpected(ParseError{std::string(path), "expected an object"});
|
||||
DownloadProvideAuthParams out;
|
||||
{
|
||||
const std::string fp = join(path, "taskId");
|
||||
const auto it = j.find("taskId");
|
||||
if (it == j.end() || it->is_null())
|
||||
return std::unexpected(ParseError{fp, "required field is missing"});
|
||||
if (!(*it).is_string()) return std::unexpected(ParseError{std::string(fp), "expected a string"});
|
||||
auto val = (*it).get<std::string>();
|
||||
out.taskId = std::move(val);
|
||||
}
|
||||
{
|
||||
const std::string fp = join(path, "username");
|
||||
const auto it = j.find("username");
|
||||
if (it == j.end() || it->is_null())
|
||||
return std::unexpected(ParseError{fp, "required field is missing"});
|
||||
if (!(*it).is_string()) return std::unexpected(ParseError{std::string(fp), "expected a string"});
|
||||
auto val = (*it).get<std::string>();
|
||||
if (val.size() > 256u) return std::unexpected(ParseError{std::string(fp), "value is longer than 256 characters"});
|
||||
out.username = std::move(val);
|
||||
}
|
||||
{
|
||||
const std::string fp = join(path, "password");
|
||||
const auto it = j.find("password");
|
||||
if (it == j.end() || it->is_null())
|
||||
return std::unexpected(ParseError{fp, "required field is missing"});
|
||||
if (!(*it).is_string()) return std::unexpected(ParseError{std::string(fp), "expected a string"});
|
||||
auto val = (*it).get<std::string>();
|
||||
if (val.size() > 1024u) return std::unexpected(ParseError{std::string(fp), "value is longer than 1024 characters"});
|
||||
out.password = std::move(val);
|
||||
}
|
||||
{
|
||||
const std::string fp = join(path, "save");
|
||||
const auto it = j.find("save");
|
||||
if (it != j.end() && !it->is_null()) {
|
||||
if (!(*it).is_boolean()) return std::unexpected(ParseError{std::string(fp), "expected a boolean"});
|
||||
auto val = (*it).get<bool>();
|
||||
out.save = std::move(val);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& j, const DownloadProvideAuthResult& v) {
|
||||
j = nlohmann::json::object();
|
||||
j["ok"] = v.ok;
|
||||
}
|
||||
|
||||
template <> Result<DownloadProvideAuthResult> parse<DownloadProvideAuthResult>(const nlohmann::json& j, std::string_view path) {
|
||||
if (!j.is_object()) return std::unexpected(ParseError{std::string(path), "expected an object"});
|
||||
DownloadProvideAuthResult out;
|
||||
{
|
||||
const std::string fp = join(path, "ok");
|
||||
const auto it = j.find("ok");
|
||||
if (it == j.end() || it->is_null())
|
||||
return std::unexpected(ParseError{fp, "required field is missing"});
|
||||
if (!(*it).is_boolean()) return std::unexpected(ParseError{std::string(fp), "expected a boolean"});
|
||||
auto val = (*it).get<bool>();
|
||||
out.ok = std::move(val);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& j, const DownloadRefreshUrlParams& v) {
|
||||
j = nlohmann::json::object();
|
||||
j["taskId"] = v.taskId;
|
||||
@@ -6895,6 +6967,7 @@ std::string_view to_string(Method m) noexcept {
|
||||
case Method::DownloadList: return "download.list";
|
||||
case Method::DownloadPause: return "download.pause";
|
||||
case Method::DownloadProbe: return "download.probe";
|
||||
case Method::DownloadProvideAuth: return "download.provideAuth";
|
||||
case Method::DownloadRefreshUrl: return "download.refreshUrl";
|
||||
case Method::DownloadRemove: return "download.remove";
|
||||
case Method::DownloadResume: return "download.resume";
|
||||
@@ -6938,6 +7011,7 @@ std::optional<Method> method_from_string(std::string_view s) noexcept {
|
||||
if (s == "download.list") return Method::DownloadList;
|
||||
if (s == "download.pause") return Method::DownloadPause;
|
||||
if (s == "download.probe") return Method::DownloadProbe;
|
||||
if (s == "download.provideAuth") return Method::DownloadProvideAuth;
|
||||
if (s == "download.refreshUrl") return Method::DownloadRefreshUrl;
|
||||
if (s == "download.remove") return Method::DownloadRemove;
|
||||
if (s == "download.resume") return Method::DownloadResume;
|
||||
@@ -6981,6 +7055,7 @@ bool is_privileged(Method m) noexcept {
|
||||
case Method::DownloadList: return false;
|
||||
case Method::DownloadPause: return false;
|
||||
case Method::DownloadProbe: return false;
|
||||
case Method::DownloadProvideAuth: return true;
|
||||
case Method::DownloadRefreshUrl: return false;
|
||||
case Method::DownloadRemove: return true;
|
||||
case Method::DownloadResume: return false;
|
||||
@@ -7025,6 +7100,7 @@ bool is_allowed_on(Method m, Transport t) noexcept {
|
||||
case Method::DownloadList: return t == Transport::Uds ? true : true;
|
||||
case Method::DownloadPause: return t == Transport::Uds ? true : true;
|
||||
case Method::DownloadProbe: return t == Transport::Uds ? true : true;
|
||||
case Method::DownloadProvideAuth: return t == Transport::Uds ? true : false;
|
||||
case Method::DownloadRefreshUrl: return t == Transport::Uds ? true : true;
|
||||
case Method::DownloadRemove: return t == Transport::Uds ? true : false;
|
||||
case Method::DownloadResume: return t == Transport::Uds ? true : true;
|
||||
@@ -7069,6 +7145,7 @@ std::int32_t deadline_ms(Method m) noexcept {
|
||||
case Method::DownloadList: return 5000;
|
||||
case Method::DownloadPause: return 5000;
|
||||
case Method::DownloadProbe: return 30000;
|
||||
case Method::DownloadProvideAuth: return 5000;
|
||||
case Method::DownloadRefreshUrl: return 30000;
|
||||
case Method::DownloadRemove: return 10000;
|
||||
case Method::DownloadResume: return 5000;
|
||||
@@ -7305,6 +7382,18 @@ nlohmann::json dispatch(Dispatcher& handler, Transport transport, const nlohmann
|
||||
nlohmann::json out = *r;
|
||||
return make_result(id, std::move(out));
|
||||
}
|
||||
case Method::DownloadProvideAuth: {
|
||||
auto p = parse<DownloadProvideAuthParams>(params, "params");
|
||||
if (!p)
|
||||
return make_error(id, ErrorCode::InvalidParams, p.error().message,
|
||||
nlohmann::json{{"path", p.error().path}});
|
||||
auto r = handler.on_download_provideAuth(*p);
|
||||
if (!r)
|
||||
return make_error(id, ErrorCode::InternalError, r.error().message,
|
||||
nlohmann::json{{"path", r.error().path}});
|
||||
nlohmann::json out = *r;
|
||||
return make_result(id, std::move(out));
|
||||
}
|
||||
case Method::DownloadRefreshUrl: {
|
||||
auto p = parse<DownloadRefreshUrlParams>(params, "params");
|
||||
if (!p)
|
||||
|
||||
Reference in New Issue
Block a user