• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nightconcept / almandine / 14846535458

05 May 2025 09:22PM UTC coverage: 32.421% (-35.5%) from 67.965%
14846535458

push

github

web-flow
fix: Change init module to be e2e testable (#17)

91 of 420 new or added lines in 11 files covered. (21.67%)

462 of 1425 relevant lines covered (32.42%)

1.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

7.69
/src/modules/update.lua
1
--[[
2
  Update Command Module
3

4
  Provides functionality to update dependencies to the latest allowed version or the absolute latest
5
  version if the `--latest` flag is provided.
6
]]
7
--
8

9
---TODO: remove this once we have a pass over this file
10
-- luacheck: ignore
11
---@class UpdateDeps
12
---@field load_manifest fun(): table, string?
13
---@field save_manifest fun(manifest: table): boolean, string?
14
---@field ensure_lib_dir fun(): nil
15
---@field downloader table
16
---@field resolve_latest_version fun(name: string): string?
17
---@field latest boolean|nil
18
---@field printer table Printer utility with stdout/stderr methods.
19

20
--- Updates all dependencies in project.lua to the latest allowed version, or to the latest available if
21
-- `--latest` is set.
22
-- @param load_manifest function Function to load the manifest.
23
-- @param save_manifest function Function to save the manifest.
24
-- @param ensure_lib_dir function Function to ensure lib dir exists.
25
-- @param utils table Utils module (must provide .downloader).
26
-- @param resolve_latest_version function Function to resolve latest version for a dependency (semver or commit).
27
-- @param _latest boolean|nil Whether to force update to absolute latest version.
28
-- @param printer function|nil Optional print function for output (default: print)
29
-- @param deps UpdateDeps Table containing dependencies and settings.
30
-- @return boolean success True if successful, false otherwise.
31
-- @return string|nil output_message Message for stdout.
32
-- @return string|nil error_message Message for stderr.
33
local function update_dependencies(
34
  load_manifest,
35
  save_manifest,
36
  ensure_lib_dir,
37
  utils,
38
  resolve_latest_version,
39
  _latest,
40
  printer,
41
  deps
42
)
NEW
43
  local load_manifest = deps.load_manifest
×
NEW
44
  local save_manifest = deps.save_manifest
×
NEW
45
  local ensure_lib_dir = deps.ensure_lib_dir
×
NEW
46
  local utils = { downloader = deps.downloader } -- Adapt to expected structure if needed
×
NEW
47
  local resolve_latest_version = deps.resolve_latest_version
×
NEW
48
  local _latest = deps.latest
×
NEW
49
  local printer = deps.printer
×
50

NEW
51
  local output_messages = {}
×
NEW
52
  local error_messages = {}
×
53

54
  printer = printer or print
×
55
  ensure_lib_dir()
×
56
  local manifest, err = load_manifest()
×
57
  if not manifest then
×
NEW
58
    table.insert(error_messages, "Failed to load manifest: " .. (err or "Unknown error"))
×
NEW
59
    return false, nil, table.concat(error_messages, "\n")
×
60
  end
61
  local updated = false
×
NEW
62
  table.insert(output_messages, "Checking for updates...")
×
63
  for name, dep in pairs(manifest.dependencies or {}) do
×
64
    local dep_tbl = dep
×
65
    if type(dep) == "string" then
×
66
      dep_tbl = { url = dep }
×
67
    end
68
    local new_version = resolve_latest_version(name)
×
69
    if new_version and dep_tbl.version ~= new_version then
×
70
      dep_tbl.version = new_version
×
NEW
71
      local current_version_str = dep_tbl.version or "(unknown)"
×
NEW
72
      table.insert(output_messages, string.format("Updating %s from %s to %s", name, current_version_str, new_version))
×
73
      updated = true
×
74
      local url = dep_tbl.url or dep
×
75
      local out_path = dep_tbl.path or ("src/lib/" .. name .. ".lua")
×
76
      local ok, err2 = utils.downloader.download(url, out_path)
×
77
      if not ok then
×
NEW
78
        table.insert(error_messages, string.format("Error: Failed to download %s: %s", name, err2 or "unknown error"))
×
79
      else
NEW
80
        table.insert(output_messages, string.format(" -> Downloaded %s successfully.", name))
×
81
      end
82
      -- If we upgraded from a string, update the manifest entry to a table
83
      manifest.dependencies[name] = dep_tbl
×
84
    end
85
  end
86
  if updated then
×
NEW
87
    table.insert(output_messages, "Saving updated manifest...")
×
NEW
88
    local ok_save, err_save = save_manifest(manifest)
×
NEW
89
    if not ok_save then
×
NEW
90
      table.insert(error_messages, "Error: Failed to save manifest: " .. (err_save or "Unknown error"))
×
91
      -- Decide if this is fatal. Let's say yes for now.
NEW
92
      return false, table.concat(output_messages, "\n"), table.concat(error_messages, "\n")
×
93
    else
NEW
94
      table.insert(output_messages, "Manifest updated.")
×
95
    end
96
  else
NEW
97
    table.insert(output_messages, "All dependencies are up-to-date.")
×
98
  end
99

100
  -- Combine messages for return
NEW
101
  local final_output = table.concat(output_messages, "\n")
×
102
  local final_error = nil
NEW
103
  if #error_messages > 0 then
×
NEW
104
    final_error = table.concat(error_messages, "\n")
×
105
  end
106

NEW
107
  return true, final_output, final_error
×
108
end
109

110
---
111
-- Prints usage/help information for the `update` command.
112
-- Usage: almd update [--latest]
113
-- Updates dependencies to the latest allowed version, or to the absolute latest if --latest is specified.
114
local function help_info()
115
  print([[
×
116
Usage: almd update [--latest]
117

118
Updates all dependencies to the latest allowed version, or to the absolute latest if --latest is specified.
119
Example:
120
  almd update
121
  almd update --latest
122
]])
×
123
end
124

125
return {
2✔
126
  update_dependencies = update_dependencies,
2✔
127
  help_info = help_info,
2✔
128
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc