Skip to content

Commit 84bdee4

Browse files
ldanilekConvex, Inc.
authored and
Convex, Inc.
committed
replace ComponentId::Root with TODOs (#26879)
GitOrigin-RevId: ea63af8d137051d9c3b9c658724cf4ed3f85ad3d
1 parent 5d05a4d commit 84bdee4

File tree

10 files changed

+35
-20
lines changed

10 files changed

+35
-20
lines changed

crates/application/src/cron_jobs/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl<RT: Runtime> CronJobExecutor<RT> {
390390
let execution_time_f64 = execution_time.as_secs_f64();
391391
let truncated_log_lines = self.truncate_log_lines(outcome.log_lines.clone());
392392

393-
let mut model = CronModel::new(&mut tx, ComponentId::Root);
393+
let mut model = CronModel::new(&mut tx, ComponentId::TODO());
394394

395395
if let Ok(ref result) = outcome.result {
396396
let truncated_result = self.truncate_result(result.clone());
@@ -435,7 +435,7 @@ impl<RT: Runtime> CronJobExecutor<RT> {
435435
// Continue without updating since the job state has changed
436436
return Ok(());
437437
};
438-
let mut model = CronModel::new(&mut tx, ComponentId::Root);
438+
let mut model = CronModel::new(&mut tx, ComponentId::TODO());
439439
let status = CronJobStatus::Err(e.to_string());
440440
model
441441
.insert_cron_job_log(&job, status, truncated_log_lines, execution_time_f64)
@@ -482,7 +482,7 @@ impl<RT: Runtime> CronJobExecutor<RT> {
482482
// Set state to in progress
483483
let mut updated_job = job.clone();
484484
updated_job.state = CronJobState::InProgress;
485-
CronModel::new(&mut tx, ComponentId::Root)
485+
CronModel::new(&mut tx, ComponentId::TODO())
486486
.update_job_state(job_id, updated_job.clone())
487487
.await?;
488488
self.database
@@ -560,7 +560,7 @@ impl<RT: Runtime> CronJobExecutor<RT> {
560560
// guess the correct behavior here is to store the executionId in the state so
561561
// we can log correctly here.
562562
let context = ExecutionContext::new(request_id, &caller);
563-
let mut model = CronModel::new(&mut tx, ComponentId::Root);
563+
let mut model = CronModel::new(&mut tx, ComponentId::TODO());
564564
model
565565
.insert_cron_job_log(&job, status, log_lines, 0.0)
566566
.await?;
@@ -638,7 +638,7 @@ impl<RT: Runtime> CronJobExecutor<RT> {
638638
// Continue without updating since the job state has changed
639639
return Ok(());
640640
};
641-
let mut model = CronModel::new(&mut tx, ComponentId::Root);
641+
let mut model = CronModel::new(&mut tx, ComponentId::TODO());
642642
model
643643
.insert_cron_job_log(expected_state, status, log_lines, execution_time)
644644
.await?;

crates/application/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ impl<RT: Runtime> Application<RT> {
802802
) -> anyhow::Result<Option<String>> {
803803
let mut tx = self.begin(identity).await?;
804804
let path = CanonicalizedComponentModulePath {
805-
component: ComponentId::Root,
805+
component: ComponentId::TODO(),
806806
module_path: path.canonicalize(),
807807
};
808808
let Some(metadata) = ModuleModel::new(&mut tx).get_metadata(path.clone()).await? else {

crates/application/src/test_helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ use crate::{
8989
};
9090

9191
pub static OBJECTS_TABLE: LazyLock<TableName> = LazyLock::new(|| "objects".parse().unwrap());
92-
pub static OBJECTS_TABLE_COMPONENT: ComponentId = ComponentId::Root;
92+
pub static OBJECTS_TABLE_COMPONENT: ComponentId = ComponentId::test_user();
9393

9494
#[derive(Default)]
9595
pub struct ApplicationFixtureArgs {

crates/application/src/tests/cron_jobs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async fn create_cron_job(
6666
BTreeMap<CronIdentifier, ParsedDocument<CronJob>>,
6767
CronModel<TestRuntime>,
6868
)> {
69-
let mut cron_model = CronModel::new(tx, ComponentId::Root);
69+
let mut cron_model = CronModel::new(tx, ComponentId::test_user());
7070
let mut map = serde_json::Map::new();
7171
map.insert(
7272
"key".to_string(),
@@ -221,7 +221,7 @@ async fn test_cron_jobs_helper(rt: TestRuntime, backend_state: BackendState) ->
221221
.table_is_empty(OBJECTS_TABLE_COMPONENT.into(), &OBJECTS_TABLE)
222222
.await?
223223
);
224-
let mut logs_query = cron_log_query(&mut tx, ComponentId::Root)?;
224+
let mut logs_query = cron_log_query(&mut tx, ComponentId::test_user())?;
225225
assert!(logs_query.next(&mut tx, Some(1)).await?.is_none());
226226

227227
// Resuming the backend should make the jobs execute.

crates/application/src/tests/source_package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub async fn assemble_package<RT: Runtime>(
7373
modifications: BTreeMap<CanonicalizedModulePath, Option<ModuleConfig>>,
7474
) -> anyhow::Result<Vec<ModuleConfig>> {
7575
let existing_modules = ModuleModel::new(tx)
76-
.get_application_modules(ComponentId::Root, module_loader)
76+
.get_application_modules(ComponentId::TODO(), module_loader)
7777
.await?;
7878
let mut modules = BTreeMap::new();
7979
for (path, module) in existing_modules {

crates/common/src/components/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ impl ComponentId {
5353
pub fn is_root(&self) -> bool {
5454
matches!(self, ComponentId::Root)
5555
}
56+
57+
/// This component should be passed in somehow -- it's not always going to
58+
/// be Root.
59+
#[allow(non_snake_case)]
60+
pub const fn TODO() -> Self {
61+
ComponentId::Root
62+
}
63+
64+
/// Component for tests where we need a user component.
65+
/// Ideally we could switch this to some other component with no test
66+
/// breakage.
67+
#[cfg(any(test, feature = "testing"))]
68+
pub const fn test_user() -> Self {
69+
ComponentId::Root
70+
}
5671
}
5772

5873
impl From<ComponentId> for TableNamespace {

crates/isolate/src/isolate2/runner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ async fn run_request<RT: Runtime>(
504504
while let Some(module_path) = stack.pop() {
505505
let module_specifier = module_specifier_from_path(&module_path)?;
506506
let path = CanonicalizedComponentModulePath {
507-
component: ComponentId::Root,
507+
component: ComponentId::TODO(),
508508
module_path: module_path.clone(),
509509
};
510510
let Some(module_metadata) = module_loader.get_module(tx, path).await? else {
@@ -842,7 +842,7 @@ impl<'a, RT: Runtime> AsyncSyscallProvider<RT> for Isolate2SyscallProvider<'a, R
842842

843843
fn component(&self) -> anyhow::Result<ComponentId> {
844844
// TODO(lee) fix when we finish isolate2.
845-
Ok(ComponentId::Root)
845+
Ok(ComponentId::TODO())
846846
}
847847

848848
fn key_broker(&self) -> &KeyBroker {

crates/isolate/src/tests/analyze.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async fn test_analyze_module(rt: TestRuntime) -> anyhow::Result<()> {
5050
let modules = {
5151
let mut tx = t.database.begin(Identity::system()).await?;
5252
ModuleModel::new(&mut tx)
53-
.get_application_modules(ComponentId::Root, t.module_loader.as_ref())
53+
.get_application_modules(ComponentId::test_user(), t.module_loader.as_ref())
5454
.await?
5555
};
5656

@@ -209,7 +209,7 @@ async fn test_analyze_http_errors(rt: TestRuntime) -> anyhow::Result<()> {
209209
let mut modules = {
210210
let mut tx = t.database.begin(Identity::system()).await?;
211211
ModuleModel::new(&mut tx)
212-
.get_application_modules(ComponentId::Root, t.module_loader.as_ref())
212+
.get_application_modules(ComponentId::test_user(), t.module_loader.as_ref())
213213
.await?
214214
};
215215

@@ -246,7 +246,7 @@ async fn test_analyze_function(rt: TestRuntime) -> anyhow::Result<()> {
246246
let modules = {
247247
let mut tx = t.database.begin(Identity::system()).await?;
248248
ModuleModel::new(&mut tx)
249-
.get_application_modules(ComponentId::Root, t.module_loader.as_ref())
249+
.get_application_modules(ComponentId::test_user(), t.module_loader.as_ref())
250250
.await?
251251
};
252252

@@ -336,7 +336,7 @@ async fn test_analyze_internal_function(rt: TestRuntime) -> anyhow::Result<()> {
336336
let modules = {
337337
let mut tx = t.database.begin(Identity::system()).await?;
338338
ModuleModel::new(&mut tx)
339-
.get_application_modules(ComponentId::Root, t.module_loader.as_ref())
339+
.get_application_modules(ComponentId::test_user(), t.module_loader.as_ref())
340340
.await?
341341
};
342342

@@ -540,7 +540,7 @@ async fn test_analyze_imports_are_none(rt: TestRuntime) -> anyhow::Result<()> {
540540
let mut modules = {
541541
let mut tx = t.database.begin(Identity::system()).await?;
542542
ModuleModel::new(&mut tx)
543-
.get_application_modules(ComponentId::Root, t.module_loader.as_ref())
543+
.get_application_modules(ComponentId::test_user(), t.module_loader.as_ref())
544544
.await?
545545
};
546546

crates/model/src/config/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'a, RT: Runtime> ConfigModel<'a, RT> {
8989
None => None,
9090
};
9191

92-
let cron_diff = CronModel::new(self.tx, ComponentId::Root)
92+
let cron_diff = CronModel::new(self.tx, ComponentId::TODO())
9393
.apply(&analyze_results)
9494
.await?;
9595

@@ -104,7 +104,7 @@ impl<'a, RT: Runtime> ConfigModel<'a, RT> {
104104

105105
let module_diff = ModuleModel::new(self.tx)
106106
.apply(
107-
ComponentId::Root,
107+
ComponentId::TODO(),
108108
modules,
109109
source_package_id,
110110
analyze_results,

crates/model/src/source_packages/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'a, RT: Runtime> SourcePackageModel<'a, RT> {
9494
let mut source_package_ids = vec![];
9595

9696
for module in ModuleModel::new(self.tx)
97-
.get_all_metadata(ComponentId::Root)
97+
.get_all_metadata(ComponentId::TODO())
9898
.await?
9999
{
100100
source_package_ids.push(module.source_package_id);

0 commit comments

Comments
 (0)