formist-cli 0.2.1__tar.gz → 0.2.3__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 (176) hide show
  1. {formist_cli-0.2.1 → formist_cli-0.2.3}/PKG-INFO +1 -1
  2. {formist_cli-0.2.1 → formist_cli-0.2.3}/pyproject.toml +1 -1
  3. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/api.py +16 -1
  4. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/uploads.py +52 -25
  5. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_upload_dir.py +15 -19
  6. formist_cli-0.2.3/tests/test_upload_timeouts.py +171 -0
  7. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_uploads.py +21 -13
  8. {formist_cli-0.2.1 → formist_cli-0.2.3}/uv.lock +1 -1
  9. {formist_cli-0.2.1 → formist_cli-0.2.3}/.claude-plugin/plugin.json +0 -0
  10. {formist_cli-0.2.1 → formist_cli-0.2.3}/.github/workflows/release.yml +0 -0
  11. {formist_cli-0.2.1 → formist_cli-0.2.3}/.github/workflows/test.yml +0 -0
  12. {formist_cli-0.2.1 → formist_cli-0.2.3}/.gitignore +0 -0
  13. {formist_cli-0.2.1 → formist_cli-0.2.3}/LICENSE +0 -0
  14. {formist_cli-0.2.1 → formist_cli-0.2.3}/README.ar.md +0 -0
  15. {formist_cli-0.2.1 → formist_cli-0.2.3}/README.fr.md +0 -0
  16. {formist_cli-0.2.1 → formist_cli-0.2.3}/README.md +0 -0
  17. {formist_cli-0.2.1 → formist_cli-0.2.3}/README.zh-CN.md +0 -0
  18. {formist_cli-0.2.1 → formist_cli-0.2.3}/docs/screenshot.png +0 -0
  19. {formist_cli-0.2.1 → formist_cli-0.2.3}/docs/screenshot.svg +0 -0
  20. {formist_cli-0.2.1 → formist_cli-0.2.3}/hooks/hooks.json +0 -0
  21. {formist_cli-0.2.1 → formist_cli-0.2.3}/monitors/monitors.json +0 -0
  22. {formist_cli-0.2.1 → formist_cli-0.2.3}/scripts/render_screenshot.py +0 -0
  23. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/__init__.py +0 -0
  24. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/__main__.py +0 -0
  25. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/airtable.py +0 -0
  26. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/alerts.py +0 -0
  27. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/chat.py +0 -0
  28. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/chats.py +0 -0
  29. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/cli.py +0 -0
  30. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/cli_support.py +0 -0
  31. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/connectors.py +0 -0
  32. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/context.py +0 -0
  33. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/diff.py +0 -0
  34. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/doctor.py +0 -0
  35. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/export.py +0 -0
  36. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/files.py +0 -0
  37. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/importer.py +0 -0
  38. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/kb.py +0 -0
  39. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/login.py +0 -0
  40. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/logs.py +0 -0
  41. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/meetings.py +0 -0
  42. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/messages.py +0 -0
  43. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/participants.py +0 -0
  44. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/plugin_hooks.py +0 -0
  45. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/prefs.py +0 -0
  46. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/privileges.py +0 -0
  47. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/projects.py +0 -0
  48. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/resolve.py +0 -0
  49. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/settings.py +0 -0
  50. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/skill_library.py +0 -0
  51. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/skills.py +0 -0
  52. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/space_plan.py +0 -0
  53. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/spaces.py +0 -0
  54. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/targets.py +0 -0
  55. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_archive.py +0 -0
  56. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_assignee.py +0 -0
  57. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_attach.py +0 -0
  58. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_check.py +0 -0
  59. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_cloud.py +0 -0
  60. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_duration.py +0 -0
  61. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_filter.py +0 -0
  62. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_format.py +0 -0
  63. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_fuzzy_date.py +0 -0
  64. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_identity.py +0 -0
  65. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_import.py +0 -0
  66. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_intake.py +0 -0
  67. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_json.py +0 -0
  68. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_lock.py +0 -0
  69. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_mirror.py +0 -0
  70. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_model.py +0 -0
  71. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_monitor.py +0 -0
  72. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_parse.py +0 -0
  73. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_paths.py +0 -0
  74. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_project.py +0 -0
  75. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_questions.py +0 -0
  76. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_queue.py +0 -0
  77. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_ref.py +0 -0
  78. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_search.py +0 -0
  79. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_serialize.py +0 -0
  80. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_sessions.py +0 -0
  81. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_status.py +0 -0
  82. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_store.py +0 -0
  83. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_title.py +0 -0
  84. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_views.py +0 -0
  85. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_width.py +0 -0
  86. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/task_yaml.py +0 -0
  87. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/tasks.py +0 -0
  88. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/textnorm.py +0 -0
  89. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/tokens.py +0 -0
  90. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/update.py +0 -0
  91. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/usage_tokens.py +0 -0
  92. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/users.py +0 -0
  93. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/whatsapp.py +0 -0
  94. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/workflow_corpus.py +0 -0
  95. {formist_cli-0.2.1 → formist_cli-0.2.3}/src/formist_cli/workflow_golden.json +0 -0
  96. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/fixtures/task_decisions/active/1-plain-task-example.md +0 -0
  97. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/fixtures/task_decisions/active/10-title-with-colon-and.md +0 -0
  98. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/fixtures/task_decisions/active/2-decision-with-two-op.md +0 -0
  99. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/fixtures/task_decisions/active/4-a-brief-for-ai.md +0 -0
  100. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/fixtures/task_decisions/active/6-a-milestone.md +0 -0
  101. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/fixtures/task_decisions/active/7-node-with-sub-questi.md +0 -0
  102. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/fixtures/task_decisions/active/8-needs-acceptance.md +0 -0
  103. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/fixtures/task_decisions/active/9-dependent-node.md +0 -0
  104. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/fixtures/task_decisions/archived/3-fyi-entry.md +0 -0
  105. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/fixtures/task_decisions/archived/5-for-the-owner.md +0 -0
  106. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_admin_flag_gate.py +0 -0
  107. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_airtable.py +0 -0
  108. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_alerts.py +0 -0
  109. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_api_and_tokens.py +0 -0
  110. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_api_uploads_transport.py +0 -0
  111. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_audit_log_shows_the_newest.py +0 -0
  112. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_chat.py +0 -0
  113. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_chat_group.py +0 -0
  114. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_chat_message.py +0 -0
  115. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_chats.py +0 -0
  116. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_cli_registration_is_unique.py +0 -0
  117. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_connector_group.py +0 -0
  118. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_connector_ops.py +0 -0
  119. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_connectors.py +0 -0
  120. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_context.py +0 -0
  121. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_diff.py +0 -0
  122. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_doctor.py +0 -0
  123. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_export.py +0 -0
  124. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_files.py +0 -0
  125. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_files_download.py +0 -0
  126. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_files_merge.py +0 -0
  127. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_grants_render.py +0 -0
  128. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_help_matches_the_write_guard.py +0 -0
  129. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_importer.py +0 -0
  130. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_kb.py +0 -0
  131. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_login.py +0 -0
  132. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_logs.py +0 -0
  133. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_meetings.py +0 -0
  134. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_messages.py +0 -0
  135. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_moved_to_fmdev.py +0 -0
  136. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_participants.py +0 -0
  137. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_plugin_hooks.py +0 -0
  138. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_plugin_manifest.py +0 -0
  139. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_prefs.py +0 -0
  140. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_privileges.py +0 -0
  141. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_projects.py +0 -0
  142. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_proposals.py +0 -0
  143. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_render_screenshot.py +0 -0
  144. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_report_provenance.py +0 -0
  145. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_resolve.py +0 -0
  146. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_settings.py +0 -0
  147. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_skill_group.py +0 -0
  148. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_skill_library_install.py +0 -0
  149. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_skills.py +0 -0
  150. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_space_plan.py +0 -0
  151. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_spaces.py +0 -0
  152. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_spaces_set_logo.py +0 -0
  153. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_stream_transport.py +0 -0
  154. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_targets.py +0 -0
  155. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_archive_read_only.py +0 -0
  156. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_check.py +0 -0
  157. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_cli.py +0 -0
  158. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_cloud.py +0 -0
  159. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_fuzzy_date.py +0 -0
  160. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_import.py +0 -0
  161. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_import_archive.py +0 -0
  162. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_mirror.py +0 -0
  163. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_monitor.py +0 -0
  164. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_nod_interop.py +0 -0
  165. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_parse_serialize.py +0 -0
  166. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_ref.py +0 -0
  167. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_sessions.py +0 -0
  168. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_store.py +0 -0
  169. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_views.py +0 -0
  170. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_workflow_parity.py +0 -0
  171. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_task_yaml.py +0 -0
  172. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_update.py +0 -0
  173. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_usage_tokens.py +0 -0
  174. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_users.py +0 -0
  175. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_users_writes.py +0 -0
  176. {formist_cli-0.2.1 → formist_cli-0.2.3}/tests/test_whatsapp.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: formist-cli
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Command-line client for Formist and Evane deployments
5
5
  Project-URL: Homepage, https://formist.ai
6
6
  Project-URL: Repository, https://github.com/WeCarbon/formist-cli
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "formist-cli"
7
- version = "0.2.1"
7
+ version = "0.2.3"
8
8
  description = "Command-line client for Formist and Evane deployments"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -42,6 +42,12 @@ DEFAULT_TIMEOUT = 30
42
42
  #: failure.
43
43
  UPLOAD_TIMEOUT = 600
44
44
 
45
+ #: Timeout for ONE resumable-upload chunk PUT (1 MiB by default). Not
46
+ #: :data:`DEFAULT_TIMEOUT`: a busy server can take longer than 30 s to answer
47
+ #: a chunk, and a 30 s limit killed whole upload batches on the spot. Long enough to ride out a busy server, short
48
+ #: enough that a dead connection is retried well inside the session's TTL.
49
+ CHUNK_TIMEOUT = 120
50
+
45
51
 
46
52
  class ApiError(Exception):
47
53
  """An API call that failed, phrased for whoever has to fix it."""
@@ -702,6 +708,15 @@ def _send(
702
708
  raise _translate_body(exc, payload, target, path) from None
703
709
  except urllib.error.URLError as exc:
704
710
  raise ApiError(_unreachable(target, exc)) from None
711
+ except (TimeoutError, OSError) as exc:
712
+ # A read timeout AFTER the request was sent, or a connection reset
713
+ # mid-response, is a bare TimeoutError / OSError, never wrapped in
714
+ # URLError. Uncaught it bypassed every retry and per-file FAILED line
715
+ # and killed a whole `fm upload DIR` batch.
716
+ # status=None: a transport failure, which callers may retry.
717
+ raise ApiError(
718
+ f"no answer from {target.api_base}{path} ({type(exc).__name__}: {exc or 'timed out'})"
719
+ ) from None
705
720
 
706
721
  if not raw:
707
722
  return None
@@ -938,7 +953,7 @@ def put_bytes(
938
953
  *,
939
954
  token: str | None = None,
940
955
  content_type: str = "application/octet-stream",
941
- timeout: int = DEFAULT_TIMEOUT,
956
+ timeout: int = CHUNK_TIMEOUT,
942
957
  ) -> object:
943
958
  """PUT raw bytes to ``path`` and return the decoded JSON body.
944
959
 
@@ -226,15 +226,56 @@ def _put_chunk_with_retry(
226
226
  raise UploadError(f"chunk {index} failed after {retries} attempts: {last}") from last
227
227
 
228
228
 
229
+ #: How many times a completion is re-asked on the SAME session.
230
+ DEFAULT_COMPLETE_ATTEMPTS = 6
231
+ _COMPLETE_BACKOFF_SECONDS = 5.0
232
+
233
+
229
234
  def complete_session(
230
- target: Target, space: str, upload_id: str, *, token: str | None, post: Caller | None = None
235
+ target: Target,
236
+ space: str,
237
+ upload_id: str,
238
+ *,
239
+ token: str | None,
240
+ post: Caller | None = None,
241
+ attempts: int = DEFAULT_COMPLETE_ATTEMPTS,
231
242
  ) -> dict:
243
+ """Finish ``upload_id`` and return ``{"item": <File>, ...}``.
244
+
245
+ Completion is where the server assembles the file AND converts it to
246
+ markdown, so it can take minutes on a busy server; it gets the long
247
+ :data:`api.UPLOAD_TIMEOUT`, not the 30 s default.
248
+
249
+ It is retried ON THIS SESSION, never by starting a new upload: the server's
250
+ completion is idempotent (a session that already produced a File returns
251
+ that File) and answers 409 while a first attempt is still assembling. A
252
+ caller that instead re-sent the whole file opened a second session for the
253
+ same bytes, and the server converted and stored the file twice while still
254
+ finishing the first. Retried: a transport failure (status None) and that 409. Anything
255
+ else is a verdict and raises at once.
256
+ """
257
+ # The real module for the constant and the exception type; `_api()` (which
258
+ # tests replace with a fake transport) only for the call itself.
259
+ from formist_cli import api
260
+
232
261
  post = post or _api().post
233
262
  path = f"{_upload_prefix(space)}/sessions/{upload_id}/complete"
234
- result = post(target, path, {}, token=token)
235
- if not isinstance(result, dict) or not isinstance(result.get("item"), dict):
236
- raise UploadError(f"complete returned an unexpected shape: {result!r}")
237
- return result
263
+ last: Exception | None = None
264
+ for attempt in range(max(1, attempts)):
265
+ try:
266
+ result = post(target, path, {}, token=token, timeout=api.UPLOAD_TIMEOUT)
267
+ except api.ApiError as exc:
268
+ status = getattr(exc, "status", None)
269
+ if status is not None and status != 409:
270
+ raise
271
+ last = exc
272
+ if attempt + 1 < attempts:
273
+ time.sleep(_COMPLETE_BACKOFF_SECONDS * (attempt + 1))
274
+ continue
275
+ if not isinstance(result, dict) or not isinstance(result.get("item"), dict):
276
+ raise UploadError(f"complete returned an unexpected shape: {result!r}")
277
+ return result
278
+ raise UploadError(f"complete did not finish after {attempts} attempts: {last}") from last
238
279
 
239
280
 
240
281
  def abort_session(
@@ -267,12 +308,12 @@ def upload_file(
267
308
  completion response (``{"item": <File dict>, "audit_id": ...}``,
268
309
  shape-identical to the one-shot route's).
269
310
 
270
- Refuses a 0-byte source before opening a network connection: a
271
- caller that uploads zero bytes and gets back a 200 is a real
272
- failure mode, and the cheapest place to catch it is before any
273
- bytes move. The size that actually landed is checked again
274
- against the completion response at the end, for the same reason:
275
- never trust what was sent, read back what arrived.
311
+ A 0-byte file is sent like any other (a session with no chunks, then
312
+ the completion): whether an empty file is acceptable is the server's
313
+ call, and an empty file whose name carries the information is a
314
+ legitimate upload. The size that actually landed is checked against
315
+ the completion response at the end: never trust what was sent, read
316
+ back what arrived.
276
317
 
277
318
  ``relative_path`` is this file's path inside a dropped directory
278
319
  (see :func:`open_session`). ``fm upload DIR`` is the caller that
@@ -282,8 +323,6 @@ def upload_file(
282
323
  if not file_path.is_file():
283
324
  raise UploadError(f"no such file: {file_path}")
284
325
  total_size = file_path.stat().st_size
285
- if total_size <= 0:
286
- raise UploadError(f"{file_path} is empty (0 bytes); refusing to upload it")
287
326
 
288
327
  filename = file_path.name
289
328
  opened = open_session(
@@ -546,14 +585,6 @@ _SKIPPED_UPLOAD_NAMES = frozenset({".DS_Store", "Thumbs.db", "__pycache__"})
546
585
  #: terminal.
547
586
  DIR_DRY_RUN_PREVIEW = 20
548
587
 
549
- #: The server refuses a 0-byte upload with 400 `empty-upload`, and
550
- #: `upload_file` already refuses one locally before opening a socket (see
551
- #: its docstring). A directory drop must not silently drop those rows from
552
- #: the count or invent placeholder content to get them past the refusal.
553
- #: This is just the label a directory upload's failure list uses so the
554
- #: reason is legible without chasing the exception text.
555
- EMPTY_FILE_REASON = "empty file (server refuses 0-byte uploads)"
556
-
557
588
 
558
589
  def walk_upload_dir(root: Path) -> list[Path]:
559
590
  """Every uploadable file under ``root``, recursively, in a stable
@@ -634,10 +665,6 @@ def cmd_upload_dir(args) -> int:
634
665
  failed: list[tuple[str, str]] = []
635
666
  for f in files:
636
667
  rel = relative_upload_path(root, f)
637
- if f.stat().st_size == 0:
638
- print(f"FAILED {rel} {EMPTY_FILE_REASON}", file=sys.stderr)
639
- failed.append((rel, EMPTY_FILE_REASON))
640
- continue
641
668
  try:
642
669
  completed = upload_file(
643
670
  eff.target,
@@ -52,8 +52,8 @@ class TestWalkUploadDir:
52
52
 
53
53
  # ===========================================================================
54
54
  # The fake transport: same shape as the plain-upload FakeServer, kept
55
- # minimal here: a directory upload's own logic (walking, per-file continue,
56
- # the empty-file label) is what these tests are for, not the chunk math
55
+ # minimal here: a directory upload's own logic (walking, per-file continue)
56
+ # is what these tests are for, not the chunk math
57
57
  # (already proven elsewhere).
58
58
  # ===========================================================================
59
59
  class FakeDirServer:
@@ -81,7 +81,7 @@ class FakeDirServer:
81
81
  "upload_id": upload_id,
82
82
  "chunk_size": max(total, 1),
83
83
  "total_size": total,
84
- "chunk_count": 1,
84
+ "chunk_count": 1 if total else 0,
85
85
  "received_chunks": [],
86
86
  "filename": body["filename"],
87
87
  "content_type": body["content_type"],
@@ -91,7 +91,7 @@ class FakeDirServer:
91
91
  if "/complete" in path:
92
92
  upload_id = path.rsplit("/", 2)[1]
93
93
  session = self.sessions[upload_id]
94
- data = self.chunks[upload_id][0]
94
+ data = self.chunks[upload_id].get(0, b"")
95
95
  file_id = str(uuid4())
96
96
  item = {"id": file_id, "name": session["filename"], "size": len(data)}
97
97
  return {"item": item, "audit_id": str(uuid4())}
@@ -198,23 +198,19 @@ class TestDirApply:
198
198
  # fm upload DIR --apply: failures are per-file, never abort the walk
199
199
  # ===========================================================================
200
200
  class TestDirApplyFailures:
201
- def test_an_empty_file_is_labelled_and_failed_without_opening_a_session(
202
- self, tmp_path, monkeypatch, capsys
203
- ):
201
+ def test_an_empty_file_is_uploaded_like_any_other(self, tmp_path, monkeypatch, capsys):
204
202
  (tmp_path / "good.txt").write_text("hello")
205
- (tmp_path / "empty.txt").write_bytes(b"")
203
+ (tmp_path / "No rent paid yet.txt").write_bytes(b"")
206
204
  server = FakeDirServer()
207
205
  _patch_effective(monkeypatch, server)
208
206
 
209
207
  rc = uploads.cmd_upload(_dir_args(file=str(tmp_path), apply=True))
210
208
 
211
- assert rc == 1
212
- combined = "".join(capsys.readouterr())
213
- assert "empty file (server refuses 0-byte uploads)" in combined
214
- assert "empty.txt" in combined
215
- # the client-side 0-byte refusal never opens a network connection for
216
- # THAT file: good.txt's session is the only one opened.
217
- assert {b["filename"] for b in server.open_bodies} == {"good.txt"}
209
+ assert rc == 0
210
+ out = capsys.readouterr()
211
+ assert "uploaded No rent paid yet.txt" in out.out, out.out
212
+ assert "\n2 uploaded, 0 failed, 2 total" in out.out + out.err
213
+ assert {b["filename"] for b in server.open_bodies} == {"good.txt", "No rent paid yet.txt"}
218
214
 
219
215
  def test_a_server_refusal_on_one_file_does_not_stop_the_rest(self, tmp_path, monkeypatch, capsys):
220
216
  (tmp_path / "good.txt").write_text("hello")
@@ -234,8 +230,8 @@ class TestDirApplyFailures:
234
230
  def test_json_summary_lists_the_failure(self, tmp_path, monkeypatch, capsys):
235
231
  import json as json_mod
236
232
 
237
- (tmp_path / "empty.txt").write_bytes(b"")
238
- server = FakeDirServer()
233
+ (tmp_path / "bad.txt").write_text("will be refused")
234
+ server = FakeDirServer(fail_names=frozenset({"bad.txt"}))
239
235
  _patch_effective(monkeypatch, server)
240
236
 
241
237
  rc = uploads.cmd_upload(_dir_args(file=str(tmp_path), apply=True, json=True))
@@ -245,5 +241,5 @@ class TestDirApplyFailures:
245
241
  # success lines, which would otherwise precede it, never printed).
246
242
  payload = json_mod.loads(capsys.readouterr().out)
247
243
  assert payload["uploaded"] == 0
248
- assert payload["failed"][0]["path"] == "empty.txt"
249
- assert "empty file" in payload["failed"][0]["reason"]
244
+ assert payload["failed"][0]["path"] == "bad.txt"
245
+ assert "simulated refusal" in payload["failed"][0]["reason"]
@@ -0,0 +1,171 @@
1
+ """Upload transport failures against a slow server.
2
+
3
+ The failure: `fm upload DIR` ran while the server was
4
+ stalled converting PDFs. A chunk PUT waited longer than its 30 s default
5
+ timeout; urllib raised a bare `TimeoutError` (never wrapped in `URLError`),
6
+ which `_send` did not catch, so it skipped the chunk retry AND the per-file
7
+ FAILED line and killed each whole batch. Wrapper scripts then
8
+ re-ran the files from scratch: a NEW upload session per retry, while the
9
+ server was still finishing the first one, so the same bytes were stored and
10
+ converted again.
11
+
12
+ Each test pins one piece of the fix and goes red without it:
13
+
14
+ 1. `_send` turns a read timeout / connection reset into a retryable
15
+ `ApiError` (status None);
16
+ 2. a chunk PUT gets `CHUNK_TIMEOUT`, a completion `UPLOAD_TIMEOUT`;
17
+ 3. a completion whose answer was lost is re-asked ON THE SAME SESSION
18
+ (one session, one File), a 409 "still assembling" is waited out, and a
19
+ real refusal is not retried;
20
+ 4. `fm upload DIR` reports a timed-out file as FAILED and carries on.
21
+ """
22
+
23
+ from __future__ import annotations
24
+
25
+ import urllib.request
26
+
27
+ import pytest
28
+ from test_uploads import SPACE, FakeServer
29
+
30
+ from formist_cli import api, uploads
31
+ from formist_cli.targets import resolve as resolve_target
32
+
33
+ LOCAL = resolve_target("127.0.0.1:8160")
34
+
35
+
36
+ @pytest.fixture(autouse=True)
37
+ def _no_backoff(monkeypatch):
38
+ monkeypatch.setattr(uploads, "_COMPLETE_BACKOFF_SECONDS", 0)
39
+ monkeypatch.setattr(uploads, "_RETRY_BACKOFF_SECONDS", 0)
40
+
41
+
42
+ @pytest.mark.parametrize("exc", [TimeoutError("The read operation timed out"), ConnectionResetError(54, "reset")])
43
+ def test_a_read_timeout_or_reset_becomes_a_retryable_api_error(monkeypatch, exc):
44
+ def _urlopen(request, timeout=None):
45
+ raise exc
46
+
47
+ monkeypatch.setattr(urllib.request, "urlopen", _urlopen)
48
+ with pytest.raises(api.ApiError) as caught:
49
+ api.put_bytes(LOCAL, "/projects/x/files/upload/sessions/u/chunks/0", b"abc")
50
+ assert caught.value.status is None
51
+
52
+
53
+ def test_chunk_and_completion_timeouts_are_not_the_30s_default(monkeypatch, tmp_path):
54
+ seen: dict[str, int] = {}
55
+
56
+ def _urlopen(request, timeout=None):
57
+ seen[request.get_method()] = timeout
58
+ raise TimeoutError("timed out")
59
+
60
+ monkeypatch.setattr(urllib.request, "urlopen", _urlopen)
61
+ with pytest.raises(api.ApiError):
62
+ api.put_bytes(LOCAL, "/p", b"abc")
63
+ assert seen["PUT"] == api.CHUNK_TIMEOUT > api.DEFAULT_TIMEOUT
64
+
65
+ server = FakeServer()
66
+ timeouts: list[int | None] = []
67
+ real_post = server.post
68
+
69
+ def post(target, path, body, *, token=None, **kw):
70
+ if "/complete" in path:
71
+ timeouts.append(kw.get("timeout"))
72
+ return real_post(target, path, body, token=token, **kw)
73
+
74
+ src = tmp_path / "a.bin"
75
+ src.write_bytes(b"abcdefgh")
76
+ uploads.upload_file(LOCAL, SPACE, src, token="t", post=post, put=server.put_bytes)
77
+ assert timeouts == [api.UPLOAD_TIMEOUT]
78
+
79
+
80
+ def _lost_answer_server():
81
+ """A completion that SUCCEEDS on the server but whose answer never arrives,
82
+ the first time; the real server's completion is idempotent, so is this."""
83
+ server = FakeServer()
84
+ real_post = server.post
85
+ state = {"completes": 0}
86
+
87
+ def post(target, path, body, *, token=None, **kw):
88
+ if "/complete" in path:
89
+ state["completes"] += 1
90
+ upload_id = path.rsplit("/", 2)[1]
91
+ existing = server.sessions[upload_id]["file_id"]
92
+ if existing:
93
+ return {"item": dict(server.files[existing]), "audit_id": None}
94
+ result = real_post(target, path, body, token=token, **kw)
95
+ if state["completes"] == 1:
96
+ raise api.ApiError("no answer (TimeoutError)")
97
+ return result
98
+ return real_post(target, path, body, token=token, **kw)
99
+
100
+ return server, post, state
101
+
102
+
103
+ def test_a_lost_completion_answer_is_re_asked_on_the_same_session(tmp_path):
104
+ server, post, state = _lost_answer_server()
105
+ src = tmp_path / "a.bin"
106
+ src.write_bytes(b"abcdefgh")
107
+ done = uploads.upload_file(LOCAL, SPACE, src, token="t", post=post, put=server.put_bytes)
108
+ assert done["item"]["size"] == 8
109
+ opened = [p for m, p in server.calls if m == "POST" and p.endswith("/sessions")]
110
+ assert len(opened) == 1, "a retry must not open a second upload session"
111
+ assert len(server.files) == 1 and state["completes"] == 2
112
+
113
+
114
+ def test_still_assembling_is_waited_out_and_a_refusal_is_not_retried(tmp_path):
115
+ server = FakeServer()
116
+ real_post = server.post
117
+ answers = {"n": 0}
118
+
119
+ def post(target, path, body, *, token=None, **kw):
120
+ if "/complete" in path:
121
+ answers["n"] += 1
122
+ if answers["n"] == 1:
123
+ raise api.ApiError("upload-assembling", status=409)
124
+ return real_post(target, path, body, token=token, **kw)
125
+
126
+ src = tmp_path / "a.bin"
127
+ src.write_bytes(b"abcdefgh")
128
+ assert uploads.upload_file(LOCAL, SPACE, src, token="t", post=post, put=server.put_bytes)["item"]["size"] == 8
129
+ assert answers["n"] == 2
130
+
131
+ refusals = {"n": 0}
132
+
133
+ def refusing(target, path, body, *, token=None, **kw):
134
+ if "/complete" in path:
135
+ refusals["n"] += 1
136
+ raise api.ApiError("upload-too-large", status=413)
137
+ return real_post(target, path, body, token=token, **kw)
138
+
139
+ with pytest.raises(api.ApiError):
140
+ uploads.upload_file(LOCAL, SPACE, src, token="t", post=refusing, put=server.put_bytes)
141
+ assert refusals["n"] == 1
142
+
143
+
144
+ def test_upload_dir_reports_a_timed_out_file_and_carries_on(monkeypatch, tmp_path, capsys):
145
+ """Through the REAL `api.put_bytes` / `_send`: urllib raises a bare
146
+ TimeoutError for one file's chunk. The batch must still upload the other
147
+ file and count the timed-out one as failed, instead of dying."""
148
+ from test_upload_dir import FakeDirServer, _dir_args, _patch_effective
149
+
150
+ (tmp_path / "ok.txt").write_text("fine")
151
+ (tmp_path / "slow.txt").write_text("stalls")
152
+
153
+ class StallingServer(FakeDirServer):
154
+ def put_bytes(self, target, path, data, *, token=None, **kw):
155
+ upload_id = path.rstrip("/").split("/")[-3]
156
+ if self.sessions[upload_id]["filename"] == "slow.txt":
157
+ def _urlopen(request, timeout=None):
158
+ raise TimeoutError("The read operation timed out")
159
+
160
+ monkeypatch.setattr(urllib.request, "urlopen", _urlopen)
161
+ return api.put_bytes(target, path, data, token=token)
162
+ return super().put_bytes(target, path, data, token=token, **kw)
163
+
164
+ server = StallingServer()
165
+ _patch_effective(monkeypatch, server)
166
+ rc = uploads.cmd_upload(_dir_args(file=str(tmp_path), apply=True))
167
+ out = capsys.readouterr()
168
+ combined = out.out + out.err
169
+ assert rc == 1
170
+ assert "uploaded ok.txt" in out.out, combined
171
+ assert "slow.txt" in combined and "\n1 uploaded, 1 failed, 2 total" in combined
@@ -236,21 +236,29 @@ class TestChunkedUploadSendsExactBytes:
236
236
  assert "audit_id" in completed
237
237
 
238
238
 
239
- class TestZeroByteUploadIsRefusedBeforeTheNetwork:
240
- def test_an_empty_file_raises_and_makes_no_calls(self, tmp_path):
241
- path = _write_file(tmp_path, "empty.pptx", b"")
239
+ class TestZeroByteUploadIsSentAndTheServerDecides:
240
+ def test_an_empty_file_opens_a_session_with_no_chunks_and_completes(self, tmp_path):
241
+ path = _write_file(tmp_path, "empty.txt", b"")
242
242
  server = FakeServer()
243
- with pytest.raises(UploadError, match="empty"):
244
- upload_file(LOCAL, SPACE, path, token="t", post=server.post, put=server.put_bytes)
245
- assert server.calls == [], "a refused upload must not touch the network at all"
246
-
247
- def test_the_control_a_nonempty_file_DOES_make_calls(self, tmp_path):
248
- """Without this, an empty `server.calls == []` up above could just mean
249
- the fake was never wired up correctly, not that the refusal fired."""
250
- path = _write_file(tmp_path, "nonempty.pptx", b"x")
243
+ completed = upload_file(LOCAL, SPACE, path, token="t", post=server.post, put=server.put_bytes)
244
+ assert completed["item"]["size"] == 0
245
+ methods = [m for m, _p in server.calls]
246
+ assert methods == ["POST", "POST"], server.calls # open, complete; nothing to PUT
247
+ assert server.files[completed["item"]["id"]]["_bytes"] == b""
248
+
249
+ def test_a_server_refusal_of_an_empty_file_is_raised_not_hidden(self, tmp_path):
250
+ from formist_cli import api
251
+
252
+ path = _write_file(tmp_path, "empty.txt", b"")
251
253
  server = FakeServer()
252
- upload_file(LOCAL, SPACE, path, token="t", post=server.post, put=server.put_bytes)
253
- assert len(server.calls) > 0
254
+
255
+ def refusing_post(target, path_, body, **kw):
256
+ if path_.endswith("/sessions"):
257
+ raise api.ApiError("empty-upload", status=400)
258
+ return server.post(target, path_, body, **kw)
259
+
260
+ with pytest.raises(api.ApiError, match="empty-upload"):
261
+ upload_file(LOCAL, SPACE, path, token="t", post=refusing_post, put=server.put_bytes)
254
262
 
255
263
 
256
264
  class TestServerRecordedSizeIsVerifiedNotTrusted:
@@ -25,7 +25,7 @@ wheels = [
25
25
 
26
26
  [[package]]
27
27
  name = "formist-cli"
28
- version = "0.2.1"
28
+ version = "0.2.3"
29
29
  source = { editable = "." }
30
30
 
31
31
  [package.dev-dependencies]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes