nsmcp::CodeUpstreamTool method compare (protected)

 <instance of nsmcp::CodeUpstreamTool[i]> compare context opts

Defined in /usr/local/ns/tcl/nsmcp/code-upstream.tcl

Parameters:
context (required)
opts (required)

Testcases:
No testcase defined.
Source code:
set name [dict get $opts name]
set doc [::nsmcp::codeMetadata $name]
if {$doc eq {} && [string first :: $name]==0} {set doc [::nsmcp::codeMetadata [string range $name 2 end]]}
if {![dict exists $doc script]} {error "local-source-file-metadata-unavailable"}
set path [string trimleft [dict get $doc script] /]
set mapping [::nsmcp::codeUpstreamMapping $path [:mappings]]
set local [::nsmcp::codeLocalComparable $name $doc]
set localObservedAt [clock seconds]
set repo [dict get $mapping repository]; set file [dict get $mapping path]
set ref [dict get $opts ref]; if {$ref eq {}} {set ref [dict get $mapping ref]}
set :requests 0
set sha [:commit $repo $ref]
set source [:source $repo $sha $file]
set remote [::nsmcp::codeStaticDefinition $source $name]
set comparison [:comparison $local $remote]
set baseline {}; set status unknown-no-baseline
if {[dict exists $mapping baselineRef] && [dict get $mapping baselineRef] ne {}} {
    set baseSha [:commit $repo [dict get $mapping baselineRef]]
    set base [::nsmcp::codeStaticDefinition [:source $repo $baseSha $file] $name]
    set baseCompare [:comparison $local $base]
    set baseDict {}; foreach {k t v} $baseCompare {dict set baseDict $k $v}
    set status [expr {[dict get $baseDict identical] ? "matches-configured-baseline" : "differs-from-configured-baseline"}]
    set baseline [list commit string $baseSha url string https://github.com/$repo/blob/$baseSha/$file comparison object $baseCompare]
}
# File history supplies candidates, not proof that each commit changes
# this procedure or fixes the diagnosed failure.
set history {}; set historyAvailable true
if {[catch {
    set records [ns_json parse [:get /repos/$repo/commits?sha=$sha&path=[ns_urlencode $file]&per_page=5 application/vnd.github+json]]
    set i 0
    foreach record [lrange $records 0 4] {
        set hash [dict get $record sha]
        if {![regexp {^[a-f0-9]{40}$} $hash]} {error "invalid-github-commit"}
        set parents {}; set j 0; set parentsAvailable [dict exists $record parents]
        if {$parentsAvailable} {
            foreach parent [lrange [dict get $record parents] 0 1] {
                set parentSha [dict get $parent sha]
                if {![regexp {^[a-f0-9]{40}$} $parentSha]} {error "invalid-github-commit"}
                lappend parents $j object [list commit string $parentSha url string https://github.com/$repo/commit/$parentSha]
                incr j
            }
        }
        set parentsComplete [expr {$parentsAvailable && [llength [dict get $record parents]]<=2}]
        lappend history $i object [list commit string $hash url string https://github.com/$repo/commit/$hash message string [string range [dict get $record commit message] 0 2047] parents array $parents parentsComplete boolean $parentsComplete]
        incr i
    }
}]} {set historyAvailable false}
set localBody [dict get $local body]; set remoteBody [dict get $remote body]
set first 0; set a [split $localBody \n]; set b [split $remoteBody \n]
while {$first<min([llength $a],[llength $b]) && [lindex $a $first] eq [lindex $b $first]} {incr first}
set localExcerpt [string range [join [lrange $a [expr {max(0,$first-3)}] [expr {$first+30}]] \n] 0 8191]
set remoteExcerpt [string range [join [lrange $b [expr {max(0,$first-3)}] [expr {$first+30}]] \n] 0 8191]
return [list {} object [list available boolean true comparisonPerformed boolean true resolutionCacheSeconds number 60 comparisonScope string literal-source server string [$context server] observedAt number [clock seconds] name string $name sourceFile string $path repository string $repo upstreamPath string $file requestedRef string $ref commit string $sha upstreamUrl string https://github.com/$repo/blob/$sha/$file localObservedAt number $localObservedAt localArguments string [dict get $local arguments] localDefinitionSha256 string [dict get $local definitionSha256] localBodySha256 string [ns_crypto::md string -digest sha256 -- $localBody] upstreamFileSha256 string [ns_crypto::md string -digest sha256 -- $source] comparison object $comparison baseline object $baseline localModificationStatus string $status upstreamFixVerified boolean false firstDifferentBodyLine number [expr {$localBody eq $remoteBody ? 0 : $first+1}] excerptStartBodyLine number [expr {max(0,$first-3)+1}] localExcerpt string $localExcerpt upstreamExcerpt string $remoteExcerpt excerptsComplete boolean [expr {$localExcerpt eq $localBody && $remoteExcerpt eq $remoteBody}] extraction object [list form string [dict get $remote form] dynamicCommands number [dict get $remote dynamicCommands] unsupportedCommands number [dict get $remote unsupportedCommands] selection string unique-literal-declaration] recentFileCommits array $history historyAvailable boolean $historyAvailable historyLimit number 5 diskCompared boolean false limitations string {Literal declaration extraction does not establish which conditional/dynamic definitions execute upstream. Equality compares exact bodies and canonical argument lists, not semantics or full object state. Generated wrappers, formatting and framework versions can cause differences. A configured baseline is an administrator assertion, not verified installation provenance. File history is bounded and not procedure-specific. Excerpts may omit other changes. An upstream fix requires connecting code changes to the observed failure; commit messages alone are insufficient. No local source was uploaded and no remote code was executed.}]]
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: