| 161 |
163
|
|
end
|
| 162 |
164
|
|
end
|
| 163 |
165
|
|
|
|
166
|
+ |
describe "the disclosure publishes its own distance from the proven revision" do
|
|
167
|
+ |
# #187 ran the forge 57 commits behind `main` for long enough for six exit
|
|
168
|
+ |
# surfaces to be proven and absent at the same time, and every tip-shaped
|
|
169
|
+ |
# check stayed green. The distance is the disclosure's own margin of error,
|
|
170
|
+ |
# so it is derived from the repository this forge serves rather than
|
|
171
|
+ |
# restated.
|
|
172
|
+ |
setup :bare_repository
|
|
173
|
+ |
|
|
174
|
+ |
test "the distance is the commit count between the running revision and the served head",
|
|
175
|
+ |
%{shas: shas} do
|
|
176
|
+ |
# Three commits on `refs/heads/main`. A node running the first is two
|
|
177
|
+ |
# behind, a node running the head is current, and each answer is a count
|
|
178
|
+ |
# `git` produced, not a number this test also computes by hand.
|
|
179
|
+ |
assert %{"known" => true, "behind" => 2} = Independence.deployment(Enum.at(shas, 0))
|
|
180
|
+ |
assert %{"known" => true, "behind" => 1} = Independence.deployment(Enum.at(shas, 1))
|
|
181
|
+ |
assert %{"known" => true, "behind" => 0} = Independence.deployment(Enum.at(shas, 2))
|
|
182
|
+ |
end
|
|
183
|
+ |
|
|
184
|
+ |
test "the ref the distance is measured to is named" do
|
|
185
|
+ |
# A distance with no ref names nothing. `RELEASE-004` binds the proof
|
|
186
|
+ |
# matrix to the candidate sha before `.githooks/pre-push` lets it reach
|
|
187
|
+ |
# this ref, which is what makes its head the proven revision.
|
|
188
|
+ |
assert Independence.projection()["deployment"]["proven_ref"] == "refs/heads/main"
|
|
189
|
+ |
end
|
|
190
|
+ |
|
|
191
|
+ |
test "a revision this forge never accepted reports no distance" do
|
|
192
|
+ |
assert %{"known" => false, "behind" => nil} =
|
|
193
|
+ |
Independence.deployment(String.duplicate("a", 40))
|
|
194
|
+ |
end
|
|
195
|
+ |
|
|
196
|
+ |
test "a running revision that is not a commit at all reports no distance" do
|
|
197
|
+ |
# The packaged image reports `"image"` until a deployment commits a sha.
|
|
198
|
+ |
# That is a real state, and it must withhold rather than guess.
|
|
199
|
+ |
assert %{"known" => false, "behind" => nil} = Independence.deployment("image")
|
|
200
|
+ |
assert %{"known" => false, "behind" => nil} = Independence.deployment(nil)
|
|
201
|
+ |
end
|
|
202
|
+ |
|
|
203
|
+ |
test "a forge that does not serve its own repository reports no distance", %{shas: shas} do
|
|
204
|
+ |
# The bound this section names. A forge withholding its own repository
|
|
205
|
+ |
# reports nothing here, exactly as `EXIT-005` and `EXIT-006` decline to
|
|
206
|
+ |
# detect a forge that withholds a log.
|
|
207
|
+ |
previous = Application.get_env(:openagents, :forge_repos)
|
|
208
|
+ |
Application.put_env(:openagents, :forge_repos, ["served-by-nobody"])
|
|
209
|
+ |
on_exit(fn -> Application.put_env(:openagents, :forge_repos, previous) end)
|
|
210
|
+ |
|
|
211
|
+ |
assert %{"known" => false, "behind" => nil} = Independence.deployment(Enum.at(shas, 0))
|
|
212
|
+ |
end
|
|
213
|
+ |
|
|
214
|
+ |
test "neither revision the distance lies between reaches the projection", %{shas: shas} do
|
|
215
|
+ |
# `STATUS-001` keeps commit shas off this page, and adding one was among
|
|
216
|
+ |
# the six mutations `EXIT-006`'s proof was confirmed against. A distance
|
|
217
|
+ |
# is a number and fits; the revisions it is a distance between do not.
|
|
218
|
+ |
published = strings(Independence.projection()) ++ strings(Independence.deployment(hd(shas)))
|
|
219
|
+ |
|
|
220
|
+ |
for sha <- shas, published_value <- published do
|
|
221
|
+ |
refute String.contains?(published_value, sha)
|
|
222
|
+ |
refute String.contains?(published_value, String.slice(sha, 0, 12))
|
|
223
|
+ |
end
|
|
224
|
+ |
end
|
|
225
|
+ |
|
|
226
|
+ |
test "the distance is read from the served repository rather than asserted" do
|
|
227
|
+ |
# The same compiled-import-table read `export_recipient_encryption` uses.
|
|
228
|
+ |
# `OpenAgents.Forge.Repos` is reached from this module for one reason —
|
|
229
|
+ |
# counting the commits between the running revision and the served head —
|
|
230
|
+ |
# so a hardcoded distance loses this call in the same commit.
|
|
231
|
+ |
{:ok, {module, [imports: imports]}} =
|
|
232
|
+ |
:beam_lib.chunks(:code.which(Independence), [:imports])
|
|
233
|
+ |
|
|
234
|
+ |
assert module == Independence
|
|
235
|
+ |
|
|
236
|
+ |
assert OpenAgents.Forge.Repos in Enum.map(imports, &elem(&1, 0)),
|
|
237
|
+ |
"EXIT-006 derives the deployment distance from a git read of the repository " <>
|
|
238
|
+ |
"this forge serves. A disclosure that stopped reading it must stop " <>
|
|
239
|
+ |
"publishing a distance."
|
|
240
|
+ |
end
|
|
241
|
+ |
|
|
242
|
+ |
test "being behind is not an independence shortfall" do
|
|
243
|
+ |
# Deliberate, and recorded in EXIT-006: a node one commit behind is not
|
|
244
|
+ |
# less independent, and folding ordinary deploy lag into `degraded` would
|
|
245
|
+ |
# make the verdict mean nothing on the day it mattered. The distance is
|
|
246
|
+ |
# published beside the verdict, never inside it.
|
|
247
|
+ |
clean_export = %{"gaps" => []}
|
|
248
|
+ |
clean_verification = %{"anchor_published" => true, "anchor_witnessed" => true}
|
|
249
|
+ |
|
|
250
|
+ |
clean_private_data = %{
|
|
251
|
+ |
"export_recipient_encryption" => true,
|
|
252
|
+ |
"encrypted_at_rest" => true
|
|
253
|
+ |
}
|
|
254
|
+ |
|
|
255
|
+ |
refute Independence.degraded?(clean_export, clean_verification, clean_private_data)
|
|
256
|
+ |
end
|
|
257
|
+ |
end
|
|
258
|
+ |
|
| 164 |
259
|
|
describe "the disclosure carries no content" do
|
| 165 |
260
|
|
test "every string in the projection is a family name, a status, or fixed vocabulary" do
|
| 166 |
261
|
|
families = Enum.map(ExportInventory.entries(), &Atom.to_string(&1.family))
|