1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// =============================================================================
// Copyright (c) 2026 Haixing Hu.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0.
// =============================================================================
//! Independent immutable property and bounded admission checks.
use qubit_fs::error::FsErrorKind;
use qubit_fs::error::FsOperation;
use crate::AsyncFileSystemContractSuite;
use crate::ContractCheckId;
use crate::ContractCheckOutcome;
use crate::ContractFailure;
use crate::FileSystemContract;
use crate::internal::check_catalog;
use crate::internal::property_expectations;
use crate::internal::verify_condition;
use crate::internal::verify_fs_error;
impl AsyncFileSystemContractSuite<'_> {
/// Executes the catalog's property entries in independent scopes.
///
/// # Returns
///
/// `Ok(())` after all catalog entries pass.
///
/// # Errors
///
/// Returns the first contract failure reported while checking an entry.
pub(super) async fn check_properties(&mut self) -> Result<(), ContractFailure> {
for spec in check_catalog::for_contract(FileSystemContract::Properties, true) {
self.check_properties_item(spec.id).await?;
}
Ok(())
}
/// Records one selected property check without preparing sibling checks.
///
/// # Parameters
///
/// - `id`: identifies the property contract check to validate and record.
///
/// # Returns
///
/// `Ok(())` after the selected check is recorded.
///
/// # Errors
///
/// Returns a contract failure if the selected check cannot be validated.
pub(super) async fn check_properties_item(&mut self, id: ContractCheckId) -> Result<(), ContractFailure> {
self.context.begin_check(id);
let expected = self.context.properties();
let actual = self.fixture.file_system().properties();
let outcome = match id {
ContractCheckId::PropertiesPathConstraints => {
let path = self
.fixture
.path("contract-properties")
.map_err(|error| ContractFailure::with_source("properties fixture path failed", error).at(id))?;
expected
.path_constraints()
.validate(&path)
.map_err(|error| ContractFailure::with_source("fixture path violates constraints", error).at(id))?;
verify_condition(
expected.path_constraints() == actual.path_constraints(),
id,
"path constraints snapshot changed",
)?;
ContractCheckOutcome::Passed
}
ContractCheckId::PropertiesLimitPathAdmission | ContractCheckId::PropertiesLimitComponentAdmission => {
match property_expectations::admission_path(id, expected)? {
Err(outcome) => outcome,
Ok(path) => {
let error = match self.fixture.file_system().stat(&path).await {
Err(error) => error,
Ok(_) => {
return Err(
ContractFailure::message_only("path limit admitted an oversized request").at(id),
);
}
};
verify_fs_error(
error,
FsErrorKind::ResourceLimitExceeded,
FsOperation::Stat,
&path,
expected.info().provider_id(),
None,
id,
)?;
ContractCheckOutcome::RejectedAsExpected
}
}
}
_ => property_expectations::check_snapshot(id, expected, actual)?,
};
let spec = check_catalog::specification(id);
self.context.record_check(id, spec.capability, outcome);
Ok(())
}
}