maxc-cli 0.4.5__tar.gz → 0.4.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/PKG-INFO +1 -1
  2. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/setup.py +1 -1
  3. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/__init__.py +1 -1
  4. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/app.py +98 -30
  5. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/backend/catalog.py +4 -1
  6. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/backend/data.py +15 -6
  7. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/cli.py +2 -2
  8. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/skills/SKILL.md +3 -1
  9. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/skills/references/bootstrap-auth.md +36 -16
  10. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/skills/references/bootstrap-flow.md +4 -2
  11. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli.egg-info/PKG-INFO +1 -1
  12. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_agent_hints_and_cli.py +7 -1
  13. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_backend_data_serialization.py +1 -1
  14. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_cli_mock.py +296 -0
  15. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_integration_real.py +1 -1
  16. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/MANIFEST.in +0 -0
  17. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/README.md +0 -0
  18. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/pyproject.toml +0 -0
  19. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/scripts/pyinstaller_entry.py +0 -0
  20. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/scripts/regression_test.py +0 -0
  21. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/setup.cfg +0 -0
  22. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/__main__.py +0 -0
  23. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/_samples.py +0 -0
  24. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/agent_platforms.py +0 -0
  25. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/audit.py +0 -0
  26. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/auth_providers.py +0 -0
  27. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/backend/__init__.py +0 -0
  28. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/backend/auth.py +0 -0
  29. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/backend/job.py +0 -0
  30. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/backend/meta.py +0 -0
  31. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/backend/odps.py +0 -0
  32. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/backend/query.py +0 -0
  33. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/cache.py +0 -0
  34. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/catalog_bootstrap.py +0 -0
  35. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/config.py +0 -0
  36. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/exceptions.py +0 -0
  37. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/help_format.py +0 -0
  38. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/helpers.py +0 -0
  39. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/masking.py +0 -0
  40. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/models.py +0 -0
  41. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/output.py +0 -0
  42. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/setting_parser.py +0 -0
  43. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/skills/agents/openai.yaml +0 -0
  44. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/skills/references/command-patterns.md +0 -0
  45. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/skills/references/json-output-format.md +0 -0
  46. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/skills/references/maxcompute-select-guide.md +0 -0
  47. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/skills/references/maxcompute-sql-notes.md +0 -0
  48. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/skills/references/partition-guide.md +0 -0
  49. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/skills/references/red-lines.md +0 -0
  50. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/skills/references/setup-install.md +0 -0
  51. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/skills/references/sql-common-errors.md +0 -0
  52. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/skills/references/sql-query-patterns.md +0 -0
  53. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/skills/references/text2sql-principles.md +0 -0
  54. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/store.py +0 -0
  55. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli/utils.py +0 -0
  56. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli.egg-info/SOURCES.txt +0 -0
  57. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli.egg-info/dependency_links.txt +0 -0
  58. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli.egg-info/entry_points.txt +0 -0
  59. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli.egg-info/requires.txt +0 -0
  60. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/src/maxc_cli.egg-info/top_level.txt +0 -0
  61. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_agent_platforms.py +0 -0
  62. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_agent_skill_commands.py +0 -0
  63. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_agent_skill_commands_context.py +0 -0
  64. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_backend_data.py +0 -0
  65. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_backend_meta.py +0 -0
  66. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_build_release_script.py +0 -0
  67. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_cache.py +0 -0
  68. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_catalog.py +0 -0
  69. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_catalog_bootstrap.py +0 -0
  70. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_cli_arg_validation.py +0 -0
  71. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_cli_query_parse_and_sanitize.py +0 -0
  72. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_compat.py +0 -0
  73. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_e2e_smoke.py +0 -0
  74. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_envelope_shape.py +0 -0
  75. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_error_self_correction.py +0 -0
  76. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_error_translation.py +0 -0
  77. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_exit_codes.py +0 -0
  78. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_external_auth.py +0 -0
  79. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_flag_hoist.py +0 -0
  80. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_help_format.py +0 -0
  81. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_help_version_e2e.py +0 -0
  82. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_helpers.py +0 -0
  83. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_helpers_csv.py +0 -0
  84. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_integration.py +0 -0
  85. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_job_improvements.py +0 -0
  86. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_masking.py +0 -0
  87. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_meta_schema_and_partition_cols.py +0 -0
  88. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_phase1_improvements.py +0 -0
  89. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_pyinstaller_bundle.py +0 -0
  90. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_query_auto_promote.py +0 -0
  91. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_query_result_csv_fallback.py +0 -0
  92. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_setting_parser.py +0 -0
  93. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_skill_cli_consistency.py +0 -0
  94. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_skill_eval.py +0 -0
  95. {maxc_cli-0.4.5 → maxc_cli-0.4.6}/tests/test_skill_renderer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maxc-cli
3
- Version: 0.4.5
3
+ Version: 0.4.6
4
4
  Summary: Agent-native MaxCompute CLI for external coding agents
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Python :: 3.9
@@ -9,7 +9,7 @@ README = ROOT / "README.md"
9
9
 
10
10
  setup(
11
11
  name="maxc-cli",
12
- version="0.4.5",
12
+ version="0.4.6",
13
13
  description="Agent-native MaxCompute CLI for external coding agents",
14
14
  long_description=README.read_text(encoding="utf-8"),
15
15
  long_description_content_type="text/markdown",
@@ -2,4 +2,4 @@
2
2
 
3
3
  __all__ = ["__version__"]
4
4
 
5
- __version__ = "0.4.5"
5
+ __version__ = "0.4.6"
@@ -126,6 +126,12 @@ class _PickerInputs:
126
126
  reselect: 'bool' = False
127
127
 
128
128
 
129
+ class ProjectPickerPending(Exception):
130
+ """Raised when non-TTY auth login can list projects but needs the caller to pick one."""
131
+ def __init__(self, projects: list):
132
+ self.projects = projects
133
+
134
+
129
135
  class MaxCApp:
130
136
  def __init__(
131
137
  self,
@@ -1262,7 +1268,7 @@ class MaxCApp:
1262
1268
 
1263
1269
  if use_catalog and self.backend is not None:
1264
1270
  catalog_matches = self.backend.catalog_search_tables(
1265
- keyword, schema=effective_schema,
1271
+ keyword, schema=effective_schema, project=project,
1266
1272
  )
1267
1273
  if catalog_matches is not None:
1268
1274
  matches = catalog_matches
@@ -1735,7 +1741,7 @@ class MaxCApp:
1735
1741
  }
1736
1742
  )
1737
1743
 
1738
- all_tables, _ = self.backend.list_tables(schema=schema_name)
1744
+ all_tables, _ = self.backend.list_tables(schema=schema_name, project=target_project)
1739
1745
  tables = all_tables
1740
1746
 
1741
1747
  if progress_callback is not None:
@@ -1830,13 +1836,16 @@ class MaxCApp:
1830
1836
  }
1831
1837
  )
1832
1838
 
1839
+ write_schema = schema_name or "default"
1840
+
1833
1841
  def fetch_and_cache(
1834
1842
  table_name: 'str',
1835
- table_schema: 'str' = "default",
1836
1843
  ) -> 'tuple[str, str | None]':
1837
1844
  try:
1838
- full_table = self.backend.describe_table(table_name)
1839
- existing = self.cache.get_cached_table(project, full_table.name, table_schema)
1845
+ full_table = self.backend.describe_table(
1846
+ table_name, project=project, schema=schema_name,
1847
+ )
1848
+ existing = self.cache.get_cached_table(project, full_table.name, write_schema)
1840
1849
  columns = [
1841
1850
  {"name": c.name, "type": c.type, "comment": c.comment}
1842
1851
  for c in full_table.columns
@@ -1847,7 +1856,7 @@ class MaxCApp:
1847
1856
  description=full_table.description,
1848
1857
  columns=columns,
1849
1858
  partitions=full_table.partitions,
1850
- schema_name=table_schema,
1859
+ schema_name=write_schema,
1851
1860
  )
1852
1861
  return ("updated" if existing else "created"), None
1853
1862
  except Exception as exc:
@@ -2615,29 +2624,63 @@ class MaxCApp:
2615
2624
 
2616
2625
  # Project / endpoint / region / tunnel — try the interactive Catalog
2617
2626
  # picker when the user did not pin a project explicitly.
2618
- (
2619
- picked_project,
2620
- derived_endpoint,
2621
- derived_region,
2622
- derived_tunnel,
2623
- picker_warnings,
2624
- ) = self._resolve_project_via_picker(
2625
- _PickerInputs(
2626
- provided_project=project,
2627
- provided_endpoint=endpoint,
2628
- provided_region=region_name,
2629
- provided_tunnel=tunnel_endpoint,
2630
- access_id=resolved_access_id,
2631
- secret=resolved_secret,
2632
- security_token=resolved_token,
2633
- catalog_endpoint=catalog_endpoint,
2634
- no_picker=no_picker,
2635
- from_env=from_env,
2636
- env_settings=env_settings,
2637
- existing_auth=existing_auth,
2638
- reselect=reselect,
2627
+ try:
2628
+ (
2629
+ picked_project,
2630
+ derived_endpoint,
2631
+ derived_region,
2632
+ derived_tunnel,
2633
+ picker_warnings,
2634
+ ) = self._resolve_project_via_picker(
2635
+ _PickerInputs(
2636
+ provided_project=project,
2637
+ provided_endpoint=endpoint,
2638
+ provided_region=region_name,
2639
+ provided_tunnel=tunnel_endpoint,
2640
+ access_id=resolved_access_id,
2641
+ secret=resolved_secret,
2642
+ security_token=resolved_token,
2643
+ catalog_endpoint=catalog_endpoint,
2644
+ no_picker=no_picker,
2645
+ from_env=from_env,
2646
+ env_settings=env_settings,
2647
+ existing_auth=existing_auth,
2648
+ reselect=reselect,
2649
+ )
2650
+ )
2651
+ except ProjectPickerPending as exc:
2652
+ projects_data = [
2653
+ {
2654
+ "project_id": p.project_id,
2655
+ "region": p.region,
2656
+ "endpoint": _catalog_bootstrap.region_to_endpoint(p.region),
2657
+ "owner": p.owner,
2658
+ "schema_enabled": p.schema_enabled,
2659
+ "description": p.description,
2660
+ }
2661
+ for p in exc.projects
2662
+ ]
2663
+ return Envelope(
2664
+ command="auth.login",
2665
+ status="pending",
2666
+ data={
2667
+ "reason": "project_selection_required",
2668
+ "projects": projects_data,
2669
+ "count": len(projects_data),
2670
+ },
2671
+ agent_hints=AgentHints(
2672
+ actions=[
2673
+ SuggestedAction(
2674
+ id="auth.login",
2675
+ title="Complete login with selected project",
2676
+ command="maxc auth login --project <project_id> --json",
2677
+ executable=False,
2678
+ placeholders={"project_id": "<project_id>"},
2679
+ ),
2680
+ ],
2681
+ warnings=[],
2682
+ ),
2639
2683
  )
2640
- )
2641
2684
 
2642
2685
  resolved_auth = AuthConfig(
2643
2686
  access_id=resolved_access_id,
@@ -3086,8 +3129,30 @@ class MaxCApp:
3086
3129
  [],
3087
3130
  )
3088
3131
 
3089
- # 2. Picker not viable → today's behavior (prompt or fail).
3132
+ # 2. Picker not viable (non-TTY or --no-picker).
3090
3133
  if inputs.no_picker or not sys.stdin.isatty():
3134
+ # Non-TTY + picker not disabled: list projects for structured output
3135
+ catalog_warning: str | None = None
3136
+ if not inputs.no_picker and not from_env:
3137
+ try:
3138
+ bootstrap_odps = _catalog_bootstrap.build_bootstrap_odps(
3139
+ access_id=inputs.access_id,
3140
+ secret_access_key=inputs.secret,
3141
+ security_token=inputs.security_token,
3142
+ endpoint=inputs.catalog_endpoint or provided_endpoint,
3143
+ )
3144
+ projects = _catalog_bootstrap.list_all_projects(bootstrap_odps)
3145
+ if projects:
3146
+ raise ProjectPickerPending(projects)
3147
+ except ProjectPickerPending:
3148
+ raise
3149
+ except Exception as exc:
3150
+ catalog_warning = (
3151
+ f"Could not list projects via Catalog API "
3152
+ f"({type(exc).__name__}: {exc}). "
3153
+ f"Falling back to saved/env config."
3154
+ )
3155
+
3091
3156
  prompted = self._resolve_login_value(
3092
3157
  provided=None,
3093
3158
  env_value=env_settings.get("project"),
@@ -3097,12 +3162,15 @@ class MaxCApp:
3097
3162
  secret=False,
3098
3163
  use_env=from_env,
3099
3164
  )
3165
+ warnings_out: list[str] = []
3166
+ if catalog_warning:
3167
+ warnings_out.append(catalog_warning)
3100
3168
  return (
3101
3169
  prompted,
3102
3170
  provided_endpoint,
3103
3171
  provided_region,
3104
3172
  provided_tunnel,
3105
- [],
3173
+ warnings_out,
3106
3174
  )
3107
3175
 
3108
3176
  # 3. Try the catalog picker.
@@ -192,6 +192,7 @@ class CatalogMixin:
192
192
  keyword: str,
193
193
  *,
194
194
  schema: 'str | None' = None,
195
+ project: 'str | None' = None,
195
196
  page_size: int = 50,
196
197
  ) -> 'list[dict[str, Any]] | None':
197
198
  """Search tables via Catalog API server-side full-text search.
@@ -199,6 +200,8 @@ class CatalogMixin:
199
200
  Args:
200
201
  keyword: Search term — matched against table name (substring).
201
202
  schema: Optional schema to scope the search.
203
+ project: Optional project to scope the search; default = config's
204
+ default_project.
202
205
  page_size: Results per page (max 100).
203
206
 
204
207
  Returns:
@@ -225,7 +228,7 @@ class CatalogMixin:
225
228
  # type=TABLE — required filter
226
229
  # project={proj} — scope to project
227
230
  parts = ["type=TABLE"]
228
- project = self.config.default_project
231
+ project = project or self.config.default_project
229
232
  if project:
230
233
  parts.append(f"project={project}")
231
234
  if keyword:
@@ -38,18 +38,27 @@ def _serialize_value(value: 'Any') -> 'Any':
38
38
  class DataMixin:
39
39
  """Mixin providing data sampling and profiling methods."""
40
40
 
41
- def _table_tunnel(self):
42
- """Return a TableTunnel for the current ODPS client.
41
+ def _table_tunnel(self, project: 'str | None' = None):
42
+ """Return a TableTunnel bound to ``project`` (or the client default).
43
43
 
44
44
  Real PyODPS `ODPS` instances do not expose a `.tunnel` attribute,
45
45
  so we construct `odps.tunnel.TableTunnel(odps=self.client)` lazily.
46
- Test doubles (FakeODPS) DO expose `.tunnel` directly honor that
47
- so existing FakeTunnel infrastructure keeps working.
46
+ The tunnel resolves tables against its own project, so a cross-project
47
+ download/upload (e.g. `--project other_proj`) MUST construct the tunnel
48
+ with that project — `create_*_session()` takes no project argument.
49
+
50
+ Test doubles (FakeODPS) DO expose `.tunnel` directly — honor that so
51
+ existing FakeTunnel infrastructure keeps working, and surface the
52
+ requested project on the instance for assertions.
48
53
  """
49
54
  existing = getattr(self.client, "tunnel", None)
50
55
  if existing is not None:
56
+ if project is not None:
57
+ existing.requested_project = project
51
58
  return existing
52
59
  from odps.tunnel import TableTunnel
60
+ if project:
61
+ return TableTunnel(odps=self.client, project=project)
53
62
  return TableTunnel(odps=self.client)
54
63
 
55
64
  def _resolve_partition_for_sample(
@@ -340,7 +349,7 @@ class DataMixin:
340
349
  create_session_kwargs["create_partition"] = True
341
350
  if schema:
342
351
  create_session_kwargs["schema"] = schema
343
- upload_session = self._table_tunnel().create_upload_session(
352
+ upload_session = self._table_tunnel(project=project or self.project).create_upload_session(
344
353
  definition.name, **create_session_kwargs,
345
354
  )
346
355
 
@@ -491,7 +500,7 @@ class DataMixin:
491
500
  download_kwargs: dict[str, Any] = {"partition_spec": partition}
492
501
  if schema:
493
502
  download_kwargs["schema"] = schema
494
- session = self._table_tunnel().create_download_session(
503
+ session = self._table_tunnel(project=project or self.project).create_download_session(
495
504
  definition.name, **download_kwargs,
496
505
  )
497
506
  total = session.count
@@ -1667,7 +1667,7 @@ def _handle_cache_build(app: MaxCApp, args: argparse.Namespace, stdout: TextIO)
1667
1667
  stdout.write("Fetching table list...\n")
1668
1668
  stdout.flush()
1669
1669
 
1670
- tables, _ = app.backend.list_tables()
1670
+ tables, _ = app.backend.list_tables(project=target_project, schema=schema_name)
1671
1671
  total = len(tables)
1672
1672
 
1673
1673
  if total == 0:
@@ -1698,7 +1698,7 @@ def _handle_cache_build(app: MaxCApp, args: argparse.Namespace, stdout: TextIO)
1698
1698
  def _do_fetch():
1699
1699
  # Use a simpler approach: only get table metadata without sample rows
1700
1700
  # to avoid potential hangs on table.head() or iterate_partitions()
1701
- table = app.backend._get_table(table_name)
1701
+ table = app.backend._get_table(table_name, project=target_project, schema=schema_name)
1702
1702
  # Force reload to get full schema info
1703
1703
  if hasattr(table, 'reload'):
1704
1704
  table.reload()
@@ -52,10 +52,11 @@ These are non-negotiable. See [references/red-lines.md](references/red-lines.md)
52
52
 
53
53
  ## Bootstrap Flow
54
54
 
55
- When `auth whoami --json` returns `configured=false` (no auth set up), follow [references/bootstrap-flow.md](references/bootstrap-flow.md) step by step. Three principles:
55
+ When `auth whoami --json` returns `configured=false` (no auth set up), follow [references/bootstrap-flow.md](references/bootstrap-flow.md) step by step. Key principles:
56
56
 
57
57
  1. **Never pick the auth method yourself** — always ask the user to choose between AK/SK and environment variables.
58
58
  2. **If `auth whoami` shows `auth_type=external`, the user is on an externally-managed credential provider — do NOT modify the auth config.** Treat the bootstrap as already done. Only `project`/`endpoint`/`schema` are safe to change (via `session set` or by re-running `auth login-external` with the same `--process-command`).
59
+ 3. **For AK/SK login, omit `--project` to discover available projects** — the CLI returns a `status="pending"` envelope listing all projects visible to the AK/SK (with endpoint/region pre-computed). Pick a project from the list (ask the user if ambiguous), then re-run with `--project <id>`. Skip this when the user already knows the target project.
59
60
 
60
61
  ## First Pass
61
62
 
@@ -209,6 +210,7 @@ For full command syntax and options, see [references/command-patterns.md](refere
209
210
  | Check who I am and where I'm pointed | `{{cli}} auth whoami --json` |
210
211
  | Set up auth from scratch | See Bootstrap Flow above |
211
212
  | Switch project/schema for this session | `{{cli}} session set --project P --schema S --json` |
213
+ | Re-select project (list available projects) | `{{cli}} auth login --reselect --json` → pick from `data.projects` → re-run with `--project` |
212
214
  | List tables | `{{cli}} meta list-tables --schema S --json` |
213
215
  | Get full schema of a table | `{{cli}} meta describe T --json` |
214
216
  | Find tables by keyword | `{{cli}} meta search KW --json` |
@@ -76,16 +76,13 @@ Then follow the matching section below.
76
76
 
77
77
  If `auth whoami` shows `auth_type=external` (or the saved config has `provider: external`), the user is on an externally-managed credential provider set up by another tool. **Do not run Step 2 or write a new auth block.** Treat the auth as already valid. Only `project`/`endpoint`/`schema` may be changed — via `{{cli}} session set ...` or by re-running `auth login-external` with the *same* `--process-command` and the new project/endpoint values.
78
78
 
79
- ### Always ask for project and endpoint
79
+ ### Project and endpoint selection
80
80
 
81
- **Regardless of auth method, always ask the user for `project` and `endpoint` explicitly.** Do not silently reuse values from an existing config file or environment variables.
81
+ **Path A (AK/SK):** omit `--project` the CLI queries the Catalog API and returns a `status="pending"` envelope listing all projects visible to the AK/SK, with endpoint/region pre-computed per project. Pick one from the list (ask the user if ambiguous), then re-run with `--project <id>` to complete login.
82
82
 
83
- If a current value is visible in the config or env, present it as a default optionbut the user must confirm or change it:
83
+ **Path B (env vars):** `--from-env` reads `MAXCOMPUTE_PROJECT` and `MAXCOMPUTE_ENDPOINT` from the shell environment. If either is missing, the command fails with a clear errorask the user to set them.
84
84
 
85
- > "Which MaxCompute project would you like to use? (current config shows: `<existing_project>`)"
86
- > "Which endpoint? (current config shows: `<existing_endpoint>`)"
87
-
88
- Never assume the existing project/endpoint is still correct.
85
+ **Explicit override:** if the user already knows the target project, pass `--project` and `--endpoint` directly to skip project discovery.
89
86
 
90
87
  ---
91
88
 
@@ -97,23 +94,33 @@ Use when the user has a long-lived AK/SK pair.
97
94
 
98
95
  - `access_key_id`
99
96
  - `access_key_secret`
100
- - `project` (MaxCompute project name)
101
- - `endpoint` (e.g. `http://service.cn-shanghai.maxcompute.aliyun.com/api`)
102
- - `region` (optional, e.g. `cn-shanghai`)
103
97
 
104
- ### Login command
98
+ The Catalog API provides `project`, `endpoint`, `region`, and `tunnel_endpoint` automatically. Only ask the user for these if they pass `--no-picker` or already know the target project.
99
+
100
+ ### Login command — Step 1: discover projects (recommended)
105
101
 
106
102
  ```bash
107
103
  {{cli}} auth login \
108
104
  --access-id "<access_key_id>" \
109
105
  --secret-access-key "<access_key_secret>" \
110
- --project "<project>" \
111
- --endpoint "<endpoint>" \
112
- --region "<region>" \
113
106
  --json
114
107
  ```
115
108
 
116
- Add `--no-validate` to save config without a remote identity check:
109
+ Returns `status="pending"` with `data.projects` a list of `{project_id, region, endpoint, owner, schema_enabled, description}`. Pick a project from the list and proceed to Step 2.
110
+
111
+ ### Login command — Step 2: complete login
112
+
113
+ ```bash
114
+ {{cli}} auth login \
115
+ --access-id "<access_key_id>" \
116
+ --secret-access-key "<access_key_secret>" \
117
+ --project "<project_id>" \
118
+ --json
119
+ ```
120
+
121
+ Returns `status="success"` with the configured identity. Endpoint/region are auto-derived from the project when omitted.
122
+
123
+ ### Login command (explicit — when user knows the target)
117
124
 
118
125
  ```bash
119
126
  {{cli}} auth login \
@@ -121,10 +128,23 @@ Add `--no-validate` to save config without a remote identity check:
121
128
  --secret-access-key "<access_key_secret>" \
122
129
  --project "<project>" \
123
130
  --endpoint "<endpoint>" \
124
- --no-validate \
131
+ --region "<region>" \
125
132
  --json
126
133
  ```
127
134
 
135
+ Add `--no-validate` to either form to save config without a remote identity check.
136
+
137
+ ### Picker flags
138
+
139
+ | Flag | Effect |
140
+ |------|--------|
141
+ | (omit `--project`) | Return pending envelope with project list from Catalog API (non-TTY) or interactive picker (TTY) |
142
+ | `--no-picker` | Disable project discovery; fall back to manual prompt for project/endpoint (CI escape hatch) |
143
+ | `--reselect` | Force project discovery even when a project is already saved in config (no effect with `--project` or `--no-picker`) |
144
+ | `--catalog-endpoint <url>` | Override the Catalog API URL (for non-China regions where auto-routing is unavailable) |
145
+
146
+ Fallback: if the Catalog API call fails (network, permissions, etc.), the CLI falls back to a manual prompt (TTY) or returns project=None (non-TTY).
147
+
128
148
  ### What it saves
129
149
 
130
150
  ```yaml
@@ -51,9 +51,11 @@ Then jump to the matching path in [bootstrap-auth.md](bootstrap-auth.md):
51
51
 
52
52
  If `auth whoami --json` shows `auth_type=external` (or `provider: external` in the saved config), the user is on an externally-managed credential provider. **Do not run Phase 2.** The auth is already set up — only `project`/`endpoint`/`schema` are safe to change via `session set` or by re-running the original `auth login-external` with updated `--project`/`--endpoint`. Treat bootstrap as complete and move to Phase 3.
53
53
 
54
- ### Always confirm project and endpoint
54
+ ### Project and endpoint
55
55
 
56
- Regardless of method, ask the user explicitly for `project` and `endpoint`. If a value is already in the config or env, present it as a default but require confirmation. See [bootstrap-auth.md](bootstrap-auth.md) §"Always ask for project and endpoint".
56
+ **Path A (AK/SK):** do NOT ask for project or endpoint upfront. Omit `--project` from `auth login` — the CLI returns a `pending` envelope listing available projects with pre-computed endpoints. Pick one (ask the user if ambiguous), then re-run with `--project <id>`. See [bootstrap-auth.md](bootstrap-auth.md) §"Project and endpoint selection".
57
+
58
+ **Path B (env vars):** `--from-env` reads project and endpoint from the shell. If either is missing, ask the user to export them before re-running.
57
59
 
58
60
  ### Dev vs production project check
59
61
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maxc-cli
3
- Version: 0.4.5
3
+ Version: 0.4.6
4
4
  Summary: Agent-native MaxCompute CLI for external coding agents
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Python :: 3.9
@@ -194,7 +194,13 @@ class _StubMetaBackend:
194
194
  return tables[:limit], len(tables) > limit
195
195
  return tables, False
196
196
 
197
- def describe_table(self, table_name: 'str', *, project: 'str | None' = None) -> 'TableDefinition':
197
+ def describe_table(
198
+ self,
199
+ table_name: 'str',
200
+ *,
201
+ project: 'str | None' = None,
202
+ schema: 'str | None' = None,
203
+ ) -> 'TableDefinition':
198
204
  time.sleep(0.01)
199
205
  return _table(table_name)
200
206
 
@@ -134,7 +134,7 @@ class _UploadHarness:
134
134
  def describe_table(self, *args, **kwargs) -> TableDefinition:
135
135
  return self._definition
136
136
 
137
- def _table_tunnel(self) -> _FakeTunnel:
137
+ def _table_tunnel(self, project: 'str | None' = None) -> _FakeTunnel:
138
138
  return self._tunnel
139
139
 
140
140
  def upload(self, *args, **kwargs):
@@ -166,9 +166,13 @@ class FakeTunnel:
166
166
 
167
167
  last_upload_session: 'FakeUploadSession | None' = None
168
168
  download_rows: 'dict[tuple, list[_FakeRecord]]' = {}
169
+ # Records the project the backend asked the tunnel to operate on, set by
170
+ # OdpsBackend._table_tunnel(project=...). None until a session is created.
171
+ last_session_project: 'str | None' = None
169
172
 
170
173
  def __init__(self):
171
174
  self.upload_store: dict[tuple, list] = {}
175
+ self.requested_project: 'str | None' = None
172
176
 
173
177
  def create_upload_session(
174
178
  self, table, partition_spec=None, overwrite=False, create_partition=False,
@@ -178,12 +182,14 @@ class FakeTunnel:
178
182
  sess.create_partition = create_partition
179
183
  sess.schema = schema
180
184
  FakeTunnel.last_upload_session = sess
185
+ FakeTunnel.last_session_project = self.requested_project
181
186
  return sess
182
187
 
183
188
  def create_download_session(self, table, partition_spec=None, schema=None):
184
189
  rows = FakeTunnel.download_rows.get((table, partition_spec), [])
185
190
  sess = FakeDownloadSession(table, partition_spec, rows)
186
191
  sess.schema = schema
192
+ FakeTunnel.last_session_project = self.requested_project
187
193
  return sess
188
194
 
189
195
 
@@ -712,6 +718,109 @@ def test_auth_login_reselect_with_no_picker_skips_picker(
712
718
  assert payload["data"]["identity"]["project"] == "old_proj"
713
719
 
714
720
 
721
+ def test_auth_login_non_tty_returns_pending_project_list(
722
+ tmp_path: 'Path', monkeypatch,
723
+ ) -> None:
724
+ """Non-TTY + no --project returns pending envelope with project list."""
725
+ clear_odps_env(monkeypatch)
726
+ isolate_home(monkeypatch, tmp_path)
727
+ from maxc_cli import catalog_bootstrap as cb
728
+
729
+ monkeypatch.setattr(cb, "build_bootstrap_odps", lambda **kw: object())
730
+ monkeypatch.setattr(
731
+ cb, "list_all_projects",
732
+ lambda odps: [
733
+ cb.ProjectInfo("proj_a_dev", "cn-hangzhou", "ALIYUN$x", True, "desc a"),
734
+ cb.ProjectInfo("proj_b_dev", "cn-shanghai", "ALIYUN$y", False, "desc b"),
735
+ ],
736
+ )
737
+ monkeypatch.setattr("sys.stdin.isatty", lambda: False)
738
+
739
+ config_path = tmp_path / "login.yaml"
740
+ code, payload, _ = run_json_command(
741
+ tmp_path,
742
+ config_path,
743
+ [
744
+ "auth", "login",
745
+ "--access-id", "AK", "--access-key-secret", "SK",
746
+ "--no-validate", "--json",
747
+ ],
748
+ )
749
+ assert code == 0
750
+ assert payload["status"] == "pending"
751
+ identity = payload["data"]["identity"]
752
+ assert identity["reason"] == "project_selection_required"
753
+ projects = identity["projects"]
754
+ assert len(projects) == 2
755
+ assert projects[0]["project_id"] == "proj_a_dev"
756
+ assert projects[0]["region"] == "cn-hangzhou"
757
+ assert "cn-hangzhou" in projects[0]["endpoint"]
758
+ assert projects[1]["project_id"] == "proj_b_dev"
759
+ assert identity["count"] == 2
760
+
761
+
762
+ def test_auth_login_non_tty_catalog_failure_falls_through(
763
+ tmp_path: 'Path', monkeypatch,
764
+ ) -> None:
765
+ """Non-TTY + catalog failure falls through to existing behavior (validation error)."""
766
+ clear_odps_env(monkeypatch)
767
+ isolate_home(monkeypatch, tmp_path)
768
+ from maxc_cli import catalog_bootstrap as cb
769
+
770
+ def _boom(**kw):
771
+ raise RuntimeError("catalog unreachable")
772
+ monkeypatch.setattr(cb, "build_bootstrap_odps", _boom)
773
+ monkeypatch.setattr("sys.stdin.isatty", lambda: False)
774
+
775
+ config_path = tmp_path / "login.yaml"
776
+ code, payload, _ = run_json_command(
777
+ tmp_path,
778
+ config_path,
779
+ [
780
+ "auth", "login",
781
+ "--access-id", "AK", "--access-key-secret", "SK",
782
+ "--endpoint", "http://service.cn-test.maxcompute.aliyun.com/api",
783
+ "--no-validate", "--json",
784
+ ],
785
+ )
786
+ # Falls through — project is None, validation fails
787
+ assert code == 1
788
+ assert payload["status"] == "failure"
789
+ assert payload["error"]["code"] == "VALIDATION_ERROR"
790
+
791
+
792
+ def test_auth_login_non_tty_no_picker_skips_catalog(
793
+ tmp_path: 'Path', monkeypatch,
794
+ ) -> None:
795
+ """Non-TTY + --no-picker must NOT try the catalog listing."""
796
+ clear_odps_env(monkeypatch)
797
+ isolate_home(monkeypatch, tmp_path)
798
+ from maxc_cli import catalog_bootstrap as cb
799
+
800
+ called = []
801
+ monkeypatch.setattr(
802
+ cb, "build_bootstrap_odps",
803
+ lambda **kw: (called.append(1) or object()),
804
+ )
805
+ monkeypatch.setattr("sys.stdin.isatty", lambda: False)
806
+
807
+ config_path = tmp_path / "login.yaml"
808
+ code, payload, _ = run_json_command(
809
+ tmp_path,
810
+ config_path,
811
+ [
812
+ "auth", "login",
813
+ "--access-id", "AK", "--access-key-secret", "SK",
814
+ "--endpoint", "http://service.cn-test.maxcompute.aliyun.com/api",
815
+ "--no-picker",
816
+ "--no-validate", "--json",
817
+ ],
818
+ )
819
+ # --no-picker: catalog never tried, project=None → validation fails
820
+ assert called == []
821
+ assert payload["status"] == "failure"
822
+
823
+
715
824
  def test_session_show_and_agent_context_work_without_auth(tmp_path: 'Path', monkeypatch) -> 'None':
716
825
  clear_odps_env(monkeypatch)
717
826
  isolate_home(monkeypatch, tmp_path)
@@ -1661,6 +1770,74 @@ def test_cache_build_passes_schema_to_backend(
1661
1770
  assert payload["data"]["cached_tables"] == 3
1662
1771
 
1663
1772
 
1773
+ def test_cache_build_routes_project_and_schema_end_to_end(tmp_path, monkeypatch):
1774
+ """cache build --project/--schema must scope BOTH the backend fetch and
1775
+ the cache write key.
1776
+
1777
+ Regression: list_tables/describe_table ignored --project (read the default
1778
+ project) and the cache write always used schema_name="default", so
1779
+ `cache build --project X --schema S` populated the wrong namespace with the
1780
+ default project's tables, and `cache status --project X --schema S` found
1781
+ nothing.
1782
+ """
1783
+ clear_odps_env(monkeypatch)
1784
+ isolate_home(monkeypatch, tmp_path)
1785
+ import odps
1786
+
1787
+ from maxc_cli.backend.meta import MetaMixin
1788
+ from maxc_cli.config import TableColumn, TableDefinition
1789
+
1790
+ monkeypatch.setattr(odps, "ODPS", FakeODPS)
1791
+
1792
+ calls: dict = {"list": [], "describe": []}
1793
+
1794
+ def fake_list_tables(self, *, schema=None, project=None):
1795
+ calls["list"].append((project, schema))
1796
+ tables = [type("T", (), {"name": n})() for n in ("tbl_a", "tbl_b")]
1797
+ return tables, False
1798
+
1799
+ def fake_describe(self, name, *, project=None, schema=None):
1800
+ calls["describe"].append((name, project, schema))
1801
+ return TableDefinition(
1802
+ name=name, description="",
1803
+ columns=[TableColumn(name="c", type="bigint")],
1804
+ partition_columns=[],
1805
+ )
1806
+
1807
+ monkeypatch.setattr(MetaMixin, "list_tables", fake_list_tables)
1808
+ monkeypatch.setattr(MetaMixin, "describe_table", fake_describe)
1809
+
1810
+ config_path = _make_config_with_odps(tmp_path) # default project = test_project
1811
+
1812
+ code, payload, _ = run_json_command(
1813
+ tmp_path, config_path,
1814
+ ["cache", "build", "--project", "other_proj", "--schema", "myschema", "--json"],
1815
+ )
1816
+ assert code == 0, payload
1817
+ assert payload["data"]["cached_tables"] == 2
1818
+
1819
+ # Backend fetch was scoped to the explicit project AND schema.
1820
+ assert calls["list"] == [("other_proj", "myschema")]
1821
+ assert calls["describe"], "describe_table was never called"
1822
+ assert all(p == "other_proj" and s == "myschema" for (_n, p, s) in calls["describe"])
1823
+
1824
+ # Cache rows landed under (other_proj, myschema) — not the default schema.
1825
+ code2, status_payload, _ = run_json_command(
1826
+ tmp_path, config_path,
1827
+ ["cache", "status", "--project", "other_proj", "--schema", "myschema", "--json"],
1828
+ )
1829
+ assert code2 == 0, status_payload
1830
+ assert status_payload["data"]["table_count"] == 2
1831
+
1832
+ # And nothing leaked into the default schema for this project.
1833
+ code3, default_payload, _ = run_json_command(
1834
+ tmp_path, config_path,
1835
+ ["cache", "status", "--project", "other_proj", "--schema", "default", "--json"],
1836
+ )
1837
+ assert code3 == 0, default_payload
1838
+ assert default_payload["data"]["table_count"] == 0
1839
+
1840
+
1664
1841
  def test_meta_search_passes_schema_to_backend(
1665
1842
  tmp_path: 'Path', monkeypatch
1666
1843
  ) -> None:
@@ -1683,6 +1860,67 @@ def test_meta_search_passes_schema_to_backend(
1683
1860
  assert any(m["table_name"] == "frpm" for m in matches)
1684
1861
 
1685
1862
 
1863
+ def test_catalog_search_tables_scopes_to_explicit_project():
1864
+ """catalog_search_tables(project=X) must scope the REST query to X.
1865
+
1866
+ Regression: the Catalog path hard-coded config.default_project, so
1867
+ `meta search --project other_proj` silently searched the default project
1868
+ (the Catalog path takes priority over cache/live fallbacks).
1869
+ """
1870
+ from maxc_cli.backend.odps import OdpsBackend
1871
+
1872
+ captured: dict = {}
1873
+
1874
+ class _FakeResp:
1875
+ text = '{"entries": []}'
1876
+
1877
+ class _FakeCatalogRest:
1878
+ endpoint = "http://catalog.example/api"
1879
+
1880
+ def request(self, url, method, params=None, curr_project=None):
1881
+ captured["query"] = params["query"]
1882
+ captured["curr_project"] = curr_project
1883
+ return _FakeResp()
1884
+
1885
+ backend = OdpsBackend.__new__(OdpsBackend)
1886
+ backend.config = type("C", (), {"default_project": "default_proj"})()
1887
+ backend._catalog_rest_cached = _FakeCatalogRest()
1888
+ backend._tenant_id_cached = "tenant123"
1889
+
1890
+ result = backend.catalog_search_tables("frpm", project="other_proj")
1891
+
1892
+ assert result == []
1893
+ assert "project=other_proj" in captured["query"]
1894
+ assert "project=default_proj" not in captured["query"]
1895
+ assert captured["curr_project"] == "other_proj"
1896
+
1897
+
1898
+ def test_catalog_search_tables_defaults_to_config_project():
1899
+ """Without an explicit project, the Catalog query falls back to default."""
1900
+ from maxc_cli.backend.odps import OdpsBackend
1901
+
1902
+ captured: dict = {}
1903
+
1904
+ class _FakeResp:
1905
+ text = '{"entries": []}'
1906
+
1907
+ class _FakeCatalogRest:
1908
+ endpoint = "http://catalog.example/api"
1909
+
1910
+ def request(self, url, method, params=None, curr_project=None):
1911
+ captured["query"] = params["query"]
1912
+ return _FakeResp()
1913
+
1914
+ backend = OdpsBackend.__new__(OdpsBackend)
1915
+ backend.config = type("C", (), {"default_project": "default_proj"})()
1916
+ backend._catalog_rest_cached = _FakeCatalogRest()
1917
+ backend._tenant_id_cached = "tenant123"
1918
+
1919
+ backend.catalog_search_tables("frpm")
1920
+
1921
+ assert "project=default_proj" in captured["query"]
1922
+
1923
+
1686
1924
  def test_meta_search_columns_passes_schema_to_backend(
1687
1925
  tmp_path: 'Path', monkeypatch
1688
1926
  ) -> None:
@@ -1738,6 +1976,7 @@ def _install_data_doubles(
1738
1976
 
1739
1977
  # Reset class-level FakeTunnel state.
1740
1978
  FakeTunnel.last_upload_session = None
1979
+ FakeTunnel.last_session_project = None
1741
1980
  FakeTunnel.download_rows = {}
1742
1981
  if download_rows is not None:
1743
1982
  key = (download_table or table_def.name, download_partition)
@@ -1987,6 +2226,63 @@ def test_cli_data_download_writes_full_partition(tmp_path, monkeypatch):
1987
2226
  assert out.read_text(encoding="utf-8") == "user_id,name\n1,alice\n2,bob\n"
1988
2227
 
1989
2228
 
2229
+ def test_cli_data_download_routes_tunnel_to_explicit_project(tmp_path, monkeypatch):
2230
+ """--project must reach the tunnel session, not just the metadata lookup.
2231
+
2232
+ Regression: tunnel was built against the client's default project, so
2233
+ `data download --project X` silently read from the default project.
2234
+ """
2235
+ clear_odps_env(monkeypatch)
2236
+ isolate_home(monkeypatch, tmp_path)
2237
+ _install_data_doubles(
2238
+ monkeypatch,
2239
+ columns=[("user_id", "bigint"), ("name", "string")],
2240
+ partition_columns=[("ds", "string")],
2241
+ download_rows=[{"user_id": 1, "name": "alice"}],
2242
+ download_partition="ds=20260508",
2243
+ )
2244
+ out = tmp_path / "out.csv"
2245
+ config_path = _make_config_with_odps(tmp_path) # default project = test_project
2246
+
2247
+ code, payload, _ = run_json_command(
2248
+ tmp_path, config_path,
2249
+ ["data", "download", "proj.sch.tbl",
2250
+ "--output", str(out),
2251
+ "--partition", "ds=20260508",
2252
+ "--project", "other_proj",
2253
+ "--json"],
2254
+ )
2255
+
2256
+ assert code == 0, payload
2257
+ assert FakeTunnel.last_session_project == "other_proj"
2258
+
2259
+
2260
+ def test_cli_data_upload_routes_tunnel_to_explicit_project(tmp_path, monkeypatch):
2261
+ """--project must reach the upload tunnel session, not just metadata."""
2262
+ clear_odps_env(monkeypatch)
2263
+ isolate_home(monkeypatch, tmp_path)
2264
+ _install_data_doubles(
2265
+ monkeypatch,
2266
+ columns=[("user_id", "bigint"), ("name", "string")],
2267
+ partition_columns=[("ds", "string")],
2268
+ )
2269
+ csv_path = tmp_path / "in.csv"
2270
+ csv_path.write_text("user_id,name\n1,alice\n", encoding="utf-8")
2271
+ config_path = _make_config_with_odps(tmp_path) # default project = test_project
2272
+
2273
+ code, payload, _ = run_json_command(
2274
+ tmp_path, config_path,
2275
+ ["data", "upload", "proj.sch.tbl",
2276
+ "--file", str(csv_path),
2277
+ "--partition", "ds=20260508",
2278
+ "--project", "other_proj",
2279
+ "--json"],
2280
+ )
2281
+
2282
+ assert code == 0, payload
2283
+ assert FakeTunnel.last_session_project == "other_proj"
2284
+
2285
+
1990
2286
  def test_cli_data_download_respects_limit_and_marks_truncated(tmp_path, monkeypatch):
1991
2287
  clear_odps_env(monkeypatch)
1992
2288
  isolate_home(monkeypatch, tmp_path)
@@ -621,7 +621,7 @@ class TestQueryExtended:
621
621
  code, data, stderr = run_cmd(["query", "SELECT 1 AS async_test", "--wait", "0", "--json"])
622
622
  assert code == 0, f"命令失败: {stderr}"
623
623
  assert data["status"] == "pending"
624
- assert "job_id" in _payload_data(data)["job"]
624
+ assert _payload_data(data).get("job_id")
625
625
 
626
626
  def test_query_with_file_output(self, run_cmd, tmp_config_dir: 'Path'):
627
627
  output_path = tmp_config_dir / "query_output.json"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes